UNPKG

2.09 kBJavaScriptView Raw
1'use strict';
2
3/**
4 * Module dependencies.
5 */
6
7var Test = require('../test');
8
9/**
10 * QUnit-style interface:
11 *
12 * suite('Array');
13 *
14 * test('#length', function() {
15 * var arr = [1,2,3];
16 * ok(arr.length == 3);
17 * });
18 *
19 * test('#indexOf()', function() {
20 * var arr = [1,2,3];
21 * ok(arr.indexOf(1) == 0);
22 * ok(arr.indexOf(2) == 1);
23 * ok(arr.indexOf(3) == 2);
24 * });
25 *
26 * suite('String');
27 *
28 * test('#length', function() {
29 * ok('foo'.length == 3);
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.before = common.before;
41 context.after = common.after;
42 context.beforeEach = common.beforeEach;
43 context.afterEach = common.afterEach;
44 context.run = mocha.options.delay && common.runWithSuite(suite);
45 /**
46 * Describe a "suite" with the given `title`.
47 */
48
49 context.suite = function (title) {
50 if (suites.length > 1) {
51 suites.shift();
52 }
53 return common.suite.create({
54 title: title,
55 file: file,
56 fn: false
57 });
58 };
59
60 /**
61 * Exclusive Suite.
62 */
63
64 context.suite.only = function (title) {
65 if (suites.length > 1) {
66 suites.shift();
67 }
68 return common.suite.only({
69 title: title,
70 file: file,
71 fn: false
72 });
73 };
74
75 /**
76 * Describe a specification or test-case
77 * with the given `title` and callback `fn`
78 * acting as a thunk.
79 */
80
81 context.test = function (title, fn) {
82 var test = new Test(title, fn);
83 test.file = file;
84 suites[0].addTest(test);
85 return test;
86 };
87
88 /**
89 * Exclusive test-case.
90 */
91
92 context.test.only = function (title, fn) {
93 return common.test.only(mocha, context.test(title, fn));
94 };
95
96 context.test.skip = common.test.skip;
97 context.test.retries = common.test.retries;
98 });
99};