UNPKG

2.28 kBJavaScriptView Raw
1'use strict';
2
3/**
4 * Module dependencies.
5 */
6
7var Test = require('../test');
8
9/**
10 * TDD-style interface:
11 *
12 * suite('Array', function() {
13 * suite('#indexOf()', function() {
14 * suiteSetup(function() {
15 *
16 * });
17 *
18 * test('should return -1 when not present', function() {
19 *
20 * });
21 *
22 * test('should return the index when present', function() {
23 *
24 * });
25 *
26 * suiteTeardown(function() {
27 *
28 * });
29 * });
30 * });
31 *
32 * @param {Suite} suite Root suite.
33 */
34module.exports = function (suite) {
35 var suites = [suite];
36
37 suite.on('pre-require', function (context, file, mocha) {
38 var common = require('./common')(suites, context, mocha);
39
40 context.setup = common.beforeEach;
41 context.teardown = common.afterEach;
42 context.suiteSetup = common.before;
43 context.suiteTeardown = common.after;
44 context.run = mocha.options.delay && common.runWithSuite(suite);
45
46 /**
47 * Describe a "suite" with the given `title` and callback `fn` containing
48 * nested suites and/or tests.
49 */
50 context.suite = function (title, fn) {
51 return common.suite.create({
52 title: title,
53 file: file,
54 fn: fn
55 });
56 };
57
58 /**
59 * Pending suite.
60 */
61 context.suite.skip = function (title, fn) {
62 return common.suite.skip({
63 title: title,
64 file: file,
65 fn: fn
66 });
67 };
68
69 /**
70 * Exclusive test-case.
71 */
72 context.suite.only = function (title, fn) {
73 return common.suite.only({
74 title: title,
75 file: file,
76 fn: fn
77 });
78 };
79
80 /**
81 * Describe a specification or test-case with the given `title` and
82 * callback `fn` acting as a thunk.
83 */
84 context.test = function (title, fn) {
85 var suite = suites[0];
86 if (suite.isPending()) {
87 fn = null;
88 }
89 var test = new Test(title, fn);
90 test.file = file;
91 suite.addTest(test);
92 return test;
93 };
94
95 /**
96 * Exclusive test-case.
97 */
98
99 context.test.only = function (title, fn) {
100 return common.test.only(mocha, context.test(title, fn));
101 };
102
103 context.test.skip = common.test.skip;
104 context.test.retries = common.test.retries;
105 });
106};