mocha 9.1.2 → 9.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/browser-entry.js +26 -16
- package/lib/browser/growl.js +5 -5
- package/lib/browser/parse-query.js +1 -1
- package/lib/browser/progress.js +6 -6
- package/lib/cli/config.js +7 -12
- package/lib/cli/run.js +1 -1
- package/lib/cli/watch-run.js +1 -4
- package/lib/context.js +5 -5
- package/lib/errors.js +1 -1
- package/lib/hook.js +2 -2
- package/lib/interfaces/bdd.js +23 -20
- package/lib/interfaces/common.js +7 -7
- package/lib/interfaces/exports.js +1 -1
- package/lib/interfaces/qunit.js +7 -7
- package/lib/interfaces/tdd.js +9 -9
- package/lib/mocha.js +56 -58
- package/lib/nodejs/buffered-worker-pool.js +17 -1
- package/lib/nodejs/esm-utils.js +18 -3
- package/lib/reporters/base.js +41 -28
- package/lib/reporters/doc.js +4 -4
- package/lib/reporters/dot.js +5 -5
- package/lib/reporters/html.js +12 -12
- package/lib/reporters/json-stream.js +4 -4
- package/lib/reporters/json.js +7 -7
- package/lib/reporters/landing.js +5 -5
- package/lib/reporters/list.js +5 -5
- package/lib/reporters/markdown.js +5 -5
- package/lib/reporters/min.js +1 -1
- package/lib/reporters/nyan.js +16 -16
- package/lib/reporters/progress.js +3 -3
- package/lib/reporters/spec.js +6 -6
- package/lib/reporters/tap.js +17 -17
- package/lib/reporters/xunit.js +9 -9
- package/lib/runnable.js +21 -21
- package/lib/runner.js +44 -47
- package/lib/stats-collector.js +7 -7
- package/lib/suite.js +44 -73
- package/lib/test.js +4 -4
- package/lib/utils.js +18 -19
- package/mocha-es2018.js +432 -449
- package/mocha.js +1246 -851
- package/mocha.js.map +1 -1
- package/package.json +38 -38
- package/CHANGELOG.md +0 -1015
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
(The MIT License)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2011-
|
|
3
|
+
Copyright (c) 2011-2022 OpenJS Foundation and contributors, https://openjsf.org
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
a copy of this software and associated documentation files (the
|
package/README.md
CHANGED
|
@@ -65,6 +65,6 @@ Finally, come [chat with the maintainers](https://gitter.im/mochajs/contributors
|
|
|
65
65
|
|
|
66
66
|
## License
|
|
67
67
|
|
|
68
|
-
Copyright 2011-
|
|
68
|
+
Copyright 2011-2022 OpenJS Foundation and contributors. Licensed [MIT](https://github.com/mochajs/mocha/blob/master/LICENSE).
|
|
69
69
|
|
|
70
70
|
[](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmochajs%2Fmocha?ref=badge_large)
|
package/browser-entry.js
CHANGED
|
@@ -40,12 +40,12 @@ var originalOnerrorHandler = global.onerror;
|
|
|
40
40
|
* Revert to original onerror handler if previously defined.
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
|
-
process.removeListener = function(e, fn) {
|
|
43
|
+
process.removeListener = function (e, fn) {
|
|
44
44
|
if (e === 'uncaughtException') {
|
|
45
45
|
if (originalOnerrorHandler) {
|
|
46
46
|
global.onerror = originalOnerrorHandler;
|
|
47
47
|
} else {
|
|
48
|
-
global.onerror = function() {};
|
|
48
|
+
global.onerror = function () {};
|
|
49
49
|
}
|
|
50
50
|
var i = uncaughtExceptionHandlers.indexOf(fn);
|
|
51
51
|
if (i !== -1) {
|
|
@@ -58,7 +58,7 @@ process.removeListener = function(e, fn) {
|
|
|
58
58
|
* Implements listenerCount for 'uncaughtException'.
|
|
59
59
|
*/
|
|
60
60
|
|
|
61
|
-
process.listenerCount = function(name) {
|
|
61
|
+
process.listenerCount = function (name) {
|
|
62
62
|
if (name === 'uncaughtException') {
|
|
63
63
|
return uncaughtExceptionHandlers.length;
|
|
64
64
|
}
|
|
@@ -69,9 +69,9 @@ process.listenerCount = function(name) {
|
|
|
69
69
|
* Implements uncaughtException listener.
|
|
70
70
|
*/
|
|
71
71
|
|
|
72
|
-
process.on = function(e, fn) {
|
|
72
|
+
process.on = function (e, fn) {
|
|
73
73
|
if (e === 'uncaughtException') {
|
|
74
|
-
global.onerror = function(err, url, line) {
|
|
74
|
+
global.onerror = function (err, url, line) {
|
|
75
75
|
fn(new Error(err + ' (' + url + ':' + line + ')'));
|
|
76
76
|
return !mocha.options.allowUncaught;
|
|
77
77
|
};
|
|
@@ -79,7 +79,7 @@ process.on = function(e, fn) {
|
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
-
process.listeners = function(e) {
|
|
82
|
+
process.listeners = function (e) {
|
|
83
83
|
if (e === 'uncaughtException') {
|
|
84
84
|
return uncaughtExceptionHandlers;
|
|
85
85
|
}
|
|
@@ -110,7 +110,7 @@ function timeslice() {
|
|
|
110
110
|
* High-performance override of Runner.immediately.
|
|
111
111
|
*/
|
|
112
112
|
|
|
113
|
-
Mocha.Runner.immediately = function(callback) {
|
|
113
|
+
Mocha.Runner.immediately = function (callback) {
|
|
114
114
|
immediateQueue.push(callback);
|
|
115
115
|
if (!immediateTimeout) {
|
|
116
116
|
immediateTimeout = setTimeout(timeslice, 0);
|
|
@@ -122,8 +122,8 @@ Mocha.Runner.immediately = function(callback) {
|
|
|
122
122
|
* This is useful when running tests in a browser because window.onerror will
|
|
123
123
|
* only receive the 'message' attribute of the Error.
|
|
124
124
|
*/
|
|
125
|
-
mocha.throwError = function(err) {
|
|
126
|
-
uncaughtExceptionHandlers.forEach(function(fn) {
|
|
125
|
+
mocha.throwError = function (err) {
|
|
126
|
+
uncaughtExceptionHandlers.forEach(function (fn) {
|
|
127
127
|
fn(err);
|
|
128
128
|
});
|
|
129
129
|
throw err;
|
|
@@ -134,7 +134,7 @@ mocha.throwError = function(err) {
|
|
|
134
134
|
* Normally this would happen in Mocha.prototype.loadFiles.
|
|
135
135
|
*/
|
|
136
136
|
|
|
137
|
-
mocha.ui = function(ui) {
|
|
137
|
+
mocha.ui = function (ui) {
|
|
138
138
|
Mocha.prototype.ui.call(this, ui);
|
|
139
139
|
this.suite.emit('pre-require', global, null, this);
|
|
140
140
|
return this;
|
|
@@ -144,7 +144,7 @@ mocha.ui = function(ui) {
|
|
|
144
144
|
* Setup mocha with the given setting options.
|
|
145
145
|
*/
|
|
146
146
|
|
|
147
|
-
mocha.setup = function(opts) {
|
|
147
|
+
mocha.setup = function (opts) {
|
|
148
148
|
if (typeof opts === 'string') {
|
|
149
149
|
opts = {ui: opts};
|
|
150
150
|
}
|
|
@@ -153,10 +153,10 @@ mocha.setup = function(opts) {
|
|
|
153
153
|
}
|
|
154
154
|
var self = this;
|
|
155
155
|
Object.keys(opts)
|
|
156
|
-
.filter(function(opt) {
|
|
156
|
+
.filter(function (opt) {
|
|
157
157
|
return opt !== 'delay';
|
|
158
158
|
})
|
|
159
|
-
.forEach(function(opt) {
|
|
159
|
+
.forEach(function (opt) {
|
|
160
160
|
if (Object.prototype.hasOwnProperty.call(opts, opt)) {
|
|
161
161
|
self[opt](opts[opt]);
|
|
162
162
|
}
|
|
@@ -168,7 +168,7 @@ mocha.setup = function(opts) {
|
|
|
168
168
|
* Run mocha, returning the Runner.
|
|
169
169
|
*/
|
|
170
170
|
|
|
171
|
-
mocha.run = function(fn) {
|
|
171
|
+
mocha.run = function (fn) {
|
|
172
172
|
var options = mocha.options;
|
|
173
173
|
mocha.globals('location');
|
|
174
174
|
|
|
@@ -183,7 +183,7 @@ mocha.run = function(fn) {
|
|
|
183
183
|
mocha.invert();
|
|
184
184
|
}
|
|
185
185
|
|
|
186
|
-
return Mocha.prototype.run.call(mocha, function(err) {
|
|
186
|
+
return Mocha.prototype.run.call(mocha, function (err) {
|
|
187
187
|
// The DOM Document is not available in Web Workers.
|
|
188
188
|
var document = global.document;
|
|
189
189
|
if (
|
|
@@ -209,8 +209,18 @@ Mocha.process = process;
|
|
|
209
209
|
/**
|
|
210
210
|
* Expose mocha.
|
|
211
211
|
*/
|
|
212
|
-
|
|
213
212
|
global.Mocha = Mocha;
|
|
214
213
|
global.mocha = mocha;
|
|
215
214
|
|
|
215
|
+
// for bundlers: enable `import {describe, it} from 'mocha'`
|
|
216
|
+
// `bdd` interface only
|
|
217
|
+
// prettier-ignore
|
|
218
|
+
[
|
|
219
|
+
'describe', 'context', 'it', 'specify',
|
|
220
|
+
'xdescribe', 'xcontext', 'xit', 'xspecify',
|
|
221
|
+
'before', 'beforeEach', 'afterEach', 'after'
|
|
222
|
+
].forEach(function(key) {
|
|
223
|
+
mocha[key] = global[key];
|
|
224
|
+
});
|
|
225
|
+
|
|
216
226
|
module.exports = mocha;
|
package/lib/browser/growl.js
CHANGED
|
@@ -23,7 +23,7 @@ var isBrowser = require('../utils').isBrowser;
|
|
|
23
23
|
* @see {@link Mocha#isGrowlCapable}
|
|
24
24
|
* @return {boolean} whether browser notification support exists
|
|
25
25
|
*/
|
|
26
|
-
exports.isCapable = function() {
|
|
26
|
+
exports.isCapable = function () {
|
|
27
27
|
var hasNotificationSupport = 'Notification' in window;
|
|
28
28
|
var hasPromiseSupport = typeof Promise === 'function';
|
|
29
29
|
return isBrowser() && hasNotificationSupport && hasPromiseSupport;
|
|
@@ -39,17 +39,17 @@ exports.isCapable = function() {
|
|
|
39
39
|
* @see {@link Mocha#_growl}
|
|
40
40
|
* @param {Runner} runner - Runner instance.
|
|
41
41
|
*/
|
|
42
|
-
exports.notify = function(runner) {
|
|
42
|
+
exports.notify = function (runner) {
|
|
43
43
|
var promise = isPermitted();
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Attempt notification.
|
|
47
47
|
*/
|
|
48
|
-
var sendNotification = function() {
|
|
48
|
+
var sendNotification = function () {
|
|
49
49
|
// If user hasn't responded yet... "No notification for you!" (Seinfeld)
|
|
50
50
|
Promise.race([promise, Promise.resolve(undefined)])
|
|
51
51
|
.then(canNotify)
|
|
52
|
-
.then(function() {
|
|
52
|
+
.then(function () {
|
|
53
53
|
display(runner);
|
|
54
54
|
})
|
|
55
55
|
.catch(notPermitted);
|
|
@@ -77,7 +77,7 @@ function isPermitted() {
|
|
|
77
77
|
return Promise.resolve(false);
|
|
78
78
|
},
|
|
79
79
|
default: function ask() {
|
|
80
|
-
return Notification.requestPermission().then(function(permission) {
|
|
80
|
+
return Notification.requestPermission().then(function (permission) {
|
|
81
81
|
return permission === 'granted';
|
|
82
82
|
});
|
|
83
83
|
}
|
package/lib/browser/progress.js
CHANGED
|
@@ -27,7 +27,7 @@ function Progress() {
|
|
|
27
27
|
* @param {number} size
|
|
28
28
|
* @return {Progress} Progress instance.
|
|
29
29
|
*/
|
|
30
|
-
Progress.prototype.size = function(size) {
|
|
30
|
+
Progress.prototype.size = function (size) {
|
|
31
31
|
this._size = size;
|
|
32
32
|
return this;
|
|
33
33
|
};
|
|
@@ -39,7 +39,7 @@ Progress.prototype.size = function(size) {
|
|
|
39
39
|
* @param {string} text
|
|
40
40
|
* @return {Progress} Progress instance.
|
|
41
41
|
*/
|
|
42
|
-
Progress.prototype.text = function(text) {
|
|
42
|
+
Progress.prototype.text = function (text) {
|
|
43
43
|
this._text = text;
|
|
44
44
|
return this;
|
|
45
45
|
};
|
|
@@ -51,7 +51,7 @@ Progress.prototype.text = function(text) {
|
|
|
51
51
|
* @param {number} size
|
|
52
52
|
* @return {Progress} Progress instance.
|
|
53
53
|
*/
|
|
54
|
-
Progress.prototype.fontSize = function(size) {
|
|
54
|
+
Progress.prototype.fontSize = function (size) {
|
|
55
55
|
this._fontSize = size;
|
|
56
56
|
return this;
|
|
57
57
|
};
|
|
@@ -62,7 +62,7 @@ Progress.prototype.fontSize = function(size) {
|
|
|
62
62
|
* @param {string} family
|
|
63
63
|
* @return {Progress} Progress instance.
|
|
64
64
|
*/
|
|
65
|
-
Progress.prototype.font = function(family) {
|
|
65
|
+
Progress.prototype.font = function (family) {
|
|
66
66
|
this._font = family;
|
|
67
67
|
return this;
|
|
68
68
|
};
|
|
@@ -73,7 +73,7 @@ Progress.prototype.font = function(family) {
|
|
|
73
73
|
* @param {number} n
|
|
74
74
|
* @return {Progress} Progress instance.
|
|
75
75
|
*/
|
|
76
|
-
Progress.prototype.update = function(n) {
|
|
76
|
+
Progress.prototype.update = function (n) {
|
|
77
77
|
this.percent = n;
|
|
78
78
|
return this;
|
|
79
79
|
};
|
|
@@ -84,7 +84,7 @@ Progress.prototype.update = function(n) {
|
|
|
84
84
|
* @param {CanvasRenderingContext2d} ctx
|
|
85
85
|
* @return {Progress} Progress instance.
|
|
86
86
|
*/
|
|
87
|
-
Progress.prototype.draw = function(ctx) {
|
|
87
|
+
Progress.prototype.draw = function (ctx) {
|
|
88
88
|
try {
|
|
89
89
|
var percent = Math.min(this.percent, 100);
|
|
90
90
|
var size = this._size;
|
package/lib/cli/config.js
CHANGED
|
@@ -30,10 +30,6 @@ exports.CONFIG_FILES = [
|
|
|
30
30
|
'.mocharc.json'
|
|
31
31
|
];
|
|
32
32
|
|
|
33
|
-
const isModuleNotFoundError = err =>
|
|
34
|
-
err.code === 'MODULE_NOT_FOUND' ||
|
|
35
|
-
err.message.indexOf('Cannot find module') !== -1;
|
|
36
|
-
|
|
37
33
|
/**
|
|
38
34
|
* Parsers for various config filetypes. Each accepts a filepath and
|
|
39
35
|
* returns an object (but could throw)
|
|
@@ -41,17 +37,16 @@ const isModuleNotFoundError = err =>
|
|
|
41
37
|
const parsers = (exports.parsers = {
|
|
42
38
|
yaml: filepath => require('js-yaml').load(fs.readFileSync(filepath, 'utf8')),
|
|
43
39
|
js: filepath => {
|
|
44
|
-
|
|
40
|
+
let cwdFilepath;
|
|
45
41
|
try {
|
|
46
|
-
debug('parsers: load
|
|
42
|
+
debug('parsers: load cwd-relative path: "%s"', path.resolve(filepath));
|
|
43
|
+
cwdFilepath = require.resolve(path.resolve(filepath)); // evtl. throws
|
|
47
44
|
return require(cwdFilepath);
|
|
48
45
|
} catch (err) {
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
throw err; // rethrow
|
|
54
|
-
}
|
|
46
|
+
if (cwdFilepath) throw err;
|
|
47
|
+
|
|
48
|
+
debug('parsers: retry load as module-relative path: "%s"', filepath);
|
|
49
|
+
return require(filepath);
|
|
55
50
|
}
|
|
56
51
|
},
|
|
57
52
|
json: filepath =>
|
package/lib/cli/run.js
CHANGED
package/lib/cli/watch-run.js
CHANGED
|
@@ -231,10 +231,7 @@ const createWatcher = (
|
|
|
231
231
|
process.stdin.resume();
|
|
232
232
|
process.stdin.setEncoding('utf8');
|
|
233
233
|
process.stdin.on('data', data => {
|
|
234
|
-
const str = data
|
|
235
|
-
.toString()
|
|
236
|
-
.trim()
|
|
237
|
-
.toLowerCase();
|
|
234
|
+
const str = data.toString().trim().toLowerCase();
|
|
238
235
|
if (str === 'rs') rerunner.scheduleRun();
|
|
239
236
|
});
|
|
240
237
|
|
package/lib/context.js
CHANGED
|
@@ -22,7 +22,7 @@ function Context() {}
|
|
|
22
22
|
* @param {Runnable} runnable
|
|
23
23
|
* @return {Context} context
|
|
24
24
|
*/
|
|
25
|
-
Context.prototype.runnable = function(runnable) {
|
|
25
|
+
Context.prototype.runnable = function (runnable) {
|
|
26
26
|
if (!arguments.length) {
|
|
27
27
|
return this._runnable;
|
|
28
28
|
}
|
|
@@ -37,7 +37,7 @@ Context.prototype.runnable = function(runnable) {
|
|
|
37
37
|
* @param {number} ms
|
|
38
38
|
* @return {Context} self
|
|
39
39
|
*/
|
|
40
|
-
Context.prototype.timeout = function(ms) {
|
|
40
|
+
Context.prototype.timeout = function (ms) {
|
|
41
41
|
if (!arguments.length) {
|
|
42
42
|
return this.runnable().timeout();
|
|
43
43
|
}
|
|
@@ -52,7 +52,7 @@ Context.prototype.timeout = function(ms) {
|
|
|
52
52
|
* @param {number} ms
|
|
53
53
|
* @return {Context} self
|
|
54
54
|
*/
|
|
55
|
-
Context.prototype.slow = function(ms) {
|
|
55
|
+
Context.prototype.slow = function (ms) {
|
|
56
56
|
if (!arguments.length) {
|
|
57
57
|
return this.runnable().slow();
|
|
58
58
|
}
|
|
@@ -66,7 +66,7 @@ Context.prototype.slow = function(ms) {
|
|
|
66
66
|
* @private
|
|
67
67
|
* @throws Pending
|
|
68
68
|
*/
|
|
69
|
-
Context.prototype.skip = function() {
|
|
69
|
+
Context.prototype.skip = function () {
|
|
70
70
|
this.runnable().skip();
|
|
71
71
|
};
|
|
72
72
|
|
|
@@ -77,7 +77,7 @@ Context.prototype.skip = function() {
|
|
|
77
77
|
* @param {number} n
|
|
78
78
|
* @return {Context} self
|
|
79
79
|
*/
|
|
80
|
-
Context.prototype.retries = function(n) {
|
|
80
|
+
Context.prototype.retries = function (n) {
|
|
81
81
|
if (!arguments.length) {
|
|
82
82
|
return this.runnable().retries();
|
|
83
83
|
}
|
package/lib/errors.js
CHANGED
package/lib/hook.js
CHANGED
|
@@ -31,7 +31,7 @@ inherits(Hook, Runnable);
|
|
|
31
31
|
/**
|
|
32
32
|
* Resets the state for a next run.
|
|
33
33
|
*/
|
|
34
|
-
Hook.prototype.reset = function() {
|
|
34
|
+
Hook.prototype.reset = function () {
|
|
35
35
|
Runnable.prototype.reset.call(this);
|
|
36
36
|
delete this._error;
|
|
37
37
|
};
|
|
@@ -44,7 +44,7 @@ Hook.prototype.reset = function() {
|
|
|
44
44
|
* @param {Error} err
|
|
45
45
|
* @return {Error}
|
|
46
46
|
*/
|
|
47
|
-
Hook.prototype.error = function(err) {
|
|
47
|
+
Hook.prototype.error = function (err) {
|
|
48
48
|
if (!arguments.length) {
|
|
49
49
|
err = this._error;
|
|
50
50
|
this._error = null;
|
package/lib/interfaces/bdd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Test = require('../test');
|
|
4
|
-
var EVENT_FILE_PRE_REQUIRE =
|
|
5
|
-
.EVENT_FILE_PRE_REQUIRE;
|
|
4
|
+
var EVENT_FILE_PRE_REQUIRE =
|
|
5
|
+
require('../suite').constants.EVENT_FILE_PRE_REQUIRE;
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* BDD-style interface:
|
|
@@ -24,7 +24,7 @@ var EVENT_FILE_PRE_REQUIRE = require('../suite').constants
|
|
|
24
24
|
module.exports = function bddInterface(suite) {
|
|
25
25
|
var suites = [suite];
|
|
26
26
|
|
|
27
|
-
suite.on(EVENT_FILE_PRE_REQUIRE, function(context, file, mocha) {
|
|
27
|
+
suite.on(EVENT_FILE_PRE_REQUIRE, function (context, file, mocha) {
|
|
28
28
|
var common = require('./common')(suites, context, mocha);
|
|
29
29
|
|
|
30
30
|
context.before = common.before;
|
|
@@ -38,7 +38,7 @@ module.exports = function bddInterface(suite) {
|
|
|
38
38
|
* and/or tests.
|
|
39
39
|
*/
|
|
40
40
|
|
|
41
|
-
context.describe = context.context = function(title, fn) {
|
|
41
|
+
context.describe = context.context = function (title, fn) {
|
|
42
42
|
return common.suite.create({
|
|
43
43
|
title: title,
|
|
44
44
|
file: file,
|
|
@@ -50,22 +50,22 @@ module.exports = function bddInterface(suite) {
|
|
|
50
50
|
* Pending describe.
|
|
51
51
|
*/
|
|
52
52
|
|
|
53
|
-
context.xdescribe =
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
53
|
+
context.xdescribe =
|
|
54
|
+
context.xcontext =
|
|
55
|
+
context.describe.skip =
|
|
56
|
+
function (title, fn) {
|
|
57
|
+
return common.suite.skip({
|
|
58
|
+
title: title,
|
|
59
|
+
file: file,
|
|
60
|
+
fn: fn
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
* Exclusive suite.
|
|
66
66
|
*/
|
|
67
67
|
|
|
68
|
-
context.describe.only = function(title, fn) {
|
|
68
|
+
context.describe.only = function (title, fn) {
|
|
69
69
|
return common.suite.only({
|
|
70
70
|
title: title,
|
|
71
71
|
file: file,
|
|
@@ -79,7 +79,7 @@ module.exports = function bddInterface(suite) {
|
|
|
79
79
|
* acting as a thunk.
|
|
80
80
|
*/
|
|
81
81
|
|
|
82
|
-
context.it = context.specify = function(title, fn) {
|
|
82
|
+
context.it = context.specify = function (title, fn) {
|
|
83
83
|
var suite = suites[0];
|
|
84
84
|
if (suite.isPending()) {
|
|
85
85
|
fn = null;
|
|
@@ -94,7 +94,7 @@ module.exports = function bddInterface(suite) {
|
|
|
94
94
|
* Exclusive test-case.
|
|
95
95
|
*/
|
|
96
96
|
|
|
97
|
-
context.it.only = function(title, fn) {
|
|
97
|
+
context.it.only = function (title, fn) {
|
|
98
98
|
return common.test.only(mocha, context.it(title, fn));
|
|
99
99
|
};
|
|
100
100
|
|
|
@@ -102,9 +102,12 @@ module.exports = function bddInterface(suite) {
|
|
|
102
102
|
* Pending test case.
|
|
103
103
|
*/
|
|
104
104
|
|
|
105
|
-
context.xit =
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
context.xit =
|
|
106
|
+
context.xspecify =
|
|
107
|
+
context.it.skip =
|
|
108
|
+
function (title) {
|
|
109
|
+
return context.it(title);
|
|
110
|
+
};
|
|
108
111
|
});
|
|
109
112
|
};
|
|
110
113
|
|
package/lib/interfaces/common.js
CHANGED
|
@@ -19,7 +19,7 @@ var createForbiddenExclusivityError = errors.createForbiddenExclusivityError;
|
|
|
19
19
|
* @param {Mocha} mocha
|
|
20
20
|
* @return {Object} An object containing common functions.
|
|
21
21
|
*/
|
|
22
|
-
module.exports = function(suites, context, mocha) {
|
|
22
|
+
module.exports = function (suites, context, mocha) {
|
|
23
23
|
/**
|
|
24
24
|
* Check if the suite should be tested.
|
|
25
25
|
*
|
|
@@ -56,7 +56,7 @@ module.exports = function(suites, context, mocha) {
|
|
|
56
56
|
* @param {string} name
|
|
57
57
|
* @param {Function} fn
|
|
58
58
|
*/
|
|
59
|
-
before: function(name, fn) {
|
|
59
|
+
before: function (name, fn) {
|
|
60
60
|
suites[0].beforeAll(name, fn);
|
|
61
61
|
},
|
|
62
62
|
|
|
@@ -66,7 +66,7 @@ module.exports = function(suites, context, mocha) {
|
|
|
66
66
|
* @param {string} name
|
|
67
67
|
* @param {Function} fn
|
|
68
68
|
*/
|
|
69
|
-
after: function(name, fn) {
|
|
69
|
+
after: function (name, fn) {
|
|
70
70
|
suites[0].afterAll(name, fn);
|
|
71
71
|
},
|
|
72
72
|
|
|
@@ -76,7 +76,7 @@ module.exports = function(suites, context, mocha) {
|
|
|
76
76
|
* @param {string} name
|
|
77
77
|
* @param {Function} fn
|
|
78
78
|
*/
|
|
79
|
-
beforeEach: function(name, fn) {
|
|
79
|
+
beforeEach: function (name, fn) {
|
|
80
80
|
suites[0].beforeEach(name, fn);
|
|
81
81
|
},
|
|
82
82
|
|
|
@@ -86,7 +86,7 @@ module.exports = function(suites, context, mocha) {
|
|
|
86
86
|
* @param {string} name
|
|
87
87
|
* @param {Function} fn
|
|
88
88
|
*/
|
|
89
|
-
afterEach: function(name, fn) {
|
|
89
|
+
afterEach: function (name, fn) {
|
|
90
90
|
suites[0].afterEach(name, fn);
|
|
91
91
|
},
|
|
92
92
|
|
|
@@ -172,7 +172,7 @@ module.exports = function(suites, context, mocha) {
|
|
|
172
172
|
* @param {Function} test
|
|
173
173
|
* @returns {*}
|
|
174
174
|
*/
|
|
175
|
-
only: function(mocha, test) {
|
|
175
|
+
only: function (mocha, test) {
|
|
176
176
|
if (mocha.options.forbidOnly) {
|
|
177
177
|
throw createForbiddenExclusivityError(mocha);
|
|
178
178
|
}
|
|
@@ -185,7 +185,7 @@ module.exports = function(suites, context, mocha) {
|
|
|
185
185
|
*
|
|
186
186
|
* @param {string} title
|
|
187
187
|
*/
|
|
188
|
-
skip: function(title) {
|
|
188
|
+
skip: function (title) {
|
|
189
189
|
context.test(title);
|
|
190
190
|
}
|
|
191
191
|
}
|
package/lib/interfaces/qunit.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Test = require('../test');
|
|
4
|
-
var EVENT_FILE_PRE_REQUIRE =
|
|
5
|
-
.EVENT_FILE_PRE_REQUIRE;
|
|
4
|
+
var EVENT_FILE_PRE_REQUIRE =
|
|
5
|
+
require('../suite').constants.EVENT_FILE_PRE_REQUIRE;
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* QUnit-style interface:
|
|
@@ -32,7 +32,7 @@ var EVENT_FILE_PRE_REQUIRE = require('../suite').constants
|
|
|
32
32
|
module.exports = function qUnitInterface(suite) {
|
|
33
33
|
var suites = [suite];
|
|
34
34
|
|
|
35
|
-
suite.on(EVENT_FILE_PRE_REQUIRE, function(context, file, mocha) {
|
|
35
|
+
suite.on(EVENT_FILE_PRE_REQUIRE, function (context, file, mocha) {
|
|
36
36
|
var common = require('./common')(suites, context, mocha);
|
|
37
37
|
|
|
38
38
|
context.before = common.before;
|
|
@@ -44,7 +44,7 @@ module.exports = function qUnitInterface(suite) {
|
|
|
44
44
|
* Describe a "suite" with the given `title`.
|
|
45
45
|
*/
|
|
46
46
|
|
|
47
|
-
context.suite = function(title) {
|
|
47
|
+
context.suite = function (title) {
|
|
48
48
|
if (suites.length > 1) {
|
|
49
49
|
suites.shift();
|
|
50
50
|
}
|
|
@@ -59,7 +59,7 @@ module.exports = function qUnitInterface(suite) {
|
|
|
59
59
|
* Exclusive Suite.
|
|
60
60
|
*/
|
|
61
61
|
|
|
62
|
-
context.suite.only = function(title) {
|
|
62
|
+
context.suite.only = function (title) {
|
|
63
63
|
if (suites.length > 1) {
|
|
64
64
|
suites.shift();
|
|
65
65
|
}
|
|
@@ -76,7 +76,7 @@ module.exports = function qUnitInterface(suite) {
|
|
|
76
76
|
* acting as a thunk.
|
|
77
77
|
*/
|
|
78
78
|
|
|
79
|
-
context.test = function(title, fn) {
|
|
79
|
+
context.test = function (title, fn) {
|
|
80
80
|
var test = new Test(title, fn);
|
|
81
81
|
test.file = file;
|
|
82
82
|
suites[0].addTest(test);
|
|
@@ -87,7 +87,7 @@ module.exports = function qUnitInterface(suite) {
|
|
|
87
87
|
* Exclusive test-case.
|
|
88
88
|
*/
|
|
89
89
|
|
|
90
|
-
context.test.only = function(title, fn) {
|
|
90
|
+
context.test.only = function (title, fn) {
|
|
91
91
|
return common.test.only(mocha, context.test(title, fn));
|
|
92
92
|
};
|
|
93
93
|
|
package/lib/interfaces/tdd.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Test = require('../test');
|
|
4
|
-
var EVENT_FILE_PRE_REQUIRE =
|
|
5
|
-
.EVENT_FILE_PRE_REQUIRE;
|
|
4
|
+
var EVENT_FILE_PRE_REQUIRE =
|
|
5
|
+
require('../suite').constants.EVENT_FILE_PRE_REQUIRE;
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* TDD-style interface:
|
|
@@ -29,10 +29,10 @@ var EVENT_FILE_PRE_REQUIRE = require('../suite').constants
|
|
|
29
29
|
*
|
|
30
30
|
* @param {Suite} suite Root suite.
|
|
31
31
|
*/
|
|
32
|
-
module.exports = function(suite) {
|
|
32
|
+
module.exports = function (suite) {
|
|
33
33
|
var suites = [suite];
|
|
34
34
|
|
|
35
|
-
suite.on(EVENT_FILE_PRE_REQUIRE, function(context, file, mocha) {
|
|
35
|
+
suite.on(EVENT_FILE_PRE_REQUIRE, function (context, file, mocha) {
|
|
36
36
|
var common = require('./common')(suites, context, mocha);
|
|
37
37
|
|
|
38
38
|
context.setup = common.beforeEach;
|
|
@@ -45,7 +45,7 @@ module.exports = function(suite) {
|
|
|
45
45
|
* Describe a "suite" with the given `title` and callback `fn` containing
|
|
46
46
|
* nested suites and/or tests.
|
|
47
47
|
*/
|
|
48
|
-
context.suite = function(title, fn) {
|
|
48
|
+
context.suite = function (title, fn) {
|
|
49
49
|
return common.suite.create({
|
|
50
50
|
title: title,
|
|
51
51
|
file: file,
|
|
@@ -56,7 +56,7 @@ module.exports = function(suite) {
|
|
|
56
56
|
/**
|
|
57
57
|
* Pending suite.
|
|
58
58
|
*/
|
|
59
|
-
context.suite.skip = function(title, fn) {
|
|
59
|
+
context.suite.skip = function (title, fn) {
|
|
60
60
|
return common.suite.skip({
|
|
61
61
|
title: title,
|
|
62
62
|
file: file,
|
|
@@ -67,7 +67,7 @@ module.exports = function(suite) {
|
|
|
67
67
|
/**
|
|
68
68
|
* Exclusive test-case.
|
|
69
69
|
*/
|
|
70
|
-
context.suite.only = function(title, fn) {
|
|
70
|
+
context.suite.only = function (title, fn) {
|
|
71
71
|
return common.suite.only({
|
|
72
72
|
title: title,
|
|
73
73
|
file: file,
|
|
@@ -79,7 +79,7 @@ module.exports = function(suite) {
|
|
|
79
79
|
* Describe a specification or test-case with the given `title` and
|
|
80
80
|
* callback `fn` acting as a thunk.
|
|
81
81
|
*/
|
|
82
|
-
context.test = function(title, fn) {
|
|
82
|
+
context.test = function (title, fn) {
|
|
83
83
|
var suite = suites[0];
|
|
84
84
|
if (suite.isPending()) {
|
|
85
85
|
fn = null;
|
|
@@ -94,7 +94,7 @@ module.exports = function(suite) {
|
|
|
94
94
|
* Exclusive test-case.
|
|
95
95
|
*/
|
|
96
96
|
|
|
97
|
-
context.test.only = function(title, fn) {
|
|
97
|
+
context.test.only = function (title, fn) {
|
|
98
98
|
return common.test.only(mocha, context.test(title, fn));
|
|
99
99
|
};
|
|
100
100
|
|