mocha 11.7.4 → 12.0.0-beta-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/README.md +1 -1
- package/bin/_mocha +2 -2
- package/bin/mocha.js +46 -44
- package/browser-entry.js +20 -20
- package/index.js +2 -2
- package/lib/browser/highlight-tags.js +6 -6
- package/lib/browser/parse-query.js +5 -5
- package/lib/browser/template.html +2 -2
- package/lib/cli/cli.js +32 -27
- package/lib/cli/collect-files.js +25 -25
- package/lib/cli/commands.js +4 -4
- package/lib/cli/config.js +26 -25
- package/lib/cli/index.js +2 -2
- package/lib/cli/init.js +19 -19
- package/lib/cli/lookup-files.js +21 -21
- package/lib/cli/node-flags.js +12 -12
- package/lib/cli/one-and-dones.js +12 -11
- package/lib/cli/options.js +49 -49
- package/lib/cli/run-helpers.js +52 -54
- package/lib/cli/run-option-metadata.js +75 -75
- package/lib/cli/run.js +164 -171
- package/lib/cli/watch-run.js +75 -75
- package/lib/context.js +1 -1
- package/lib/error-constants.js +17 -17
- package/lib/errors.js +36 -29
- package/lib/hook.js +9 -9
- package/lib/interfaces/bdd.js +8 -8
- package/lib/interfaces/common.js +12 -12
- package/lib/interfaces/exports.js +8 -8
- package/lib/interfaces/index.js +5 -5
- package/lib/interfaces/qunit.js +7 -7
- package/lib/interfaces/tdd.js +7 -7
- package/lib/mocha.js +97 -97
- package/lib/nodejs/buffered-worker-pool.js +30 -30
- package/lib/nodejs/esm-utils.js +23 -20
- package/lib/nodejs/file-unloader.js +2 -2
- package/lib/nodejs/parallel-buffered-runner.js +67 -67
- package/lib/nodejs/reporters/parallel-buffered.js +13 -10
- package/lib/nodejs/serializer.js +47 -47
- package/lib/nodejs/worker.js +38 -38
- package/lib/pending.js +1 -1
- package/lib/plugin-loader.js +48 -48
- package/lib/reporters/base.js +97 -94
- package/lib/reporters/doc.js +17 -17
- package/lib/reporters/dot.js +14 -14
- package/lib/reporters/html.js +73 -67
- package/lib/reporters/index.js +16 -16
- package/lib/reporters/json-stream.js +10 -10
- package/lib/reporters/json.js +16 -16
- package/lib/reporters/landing.js +20 -20
- package/lib/reporters/list.js +10 -10
- package/lib/reporters/markdown.js +21 -21
- package/lib/reporters/min.js +7 -7
- package/lib/reporters/nyan.js +35 -35
- package/lib/reporters/progress.js +14 -14
- package/lib/reporters/spec.js +15 -15
- package/lib/reporters/tap.js +26 -26
- package/lib/reporters/xunit.js +38 -34
- package/lib/runnable.js +41 -41
- package/lib/runner.js +105 -105
- package/lib/stats-collector.js +4 -4
- package/lib/suite.js +46 -46
- package/lib/test.js +10 -10
- package/lib/utils.js +137 -122
- package/mocha.css +68 -50
- package/mocha.js +841 -806
- package/mocha.js.map +1 -1
- package/package.json +7 -14
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<a href="https://www.npmjs.com/package/mocha"><img src="https://img.shields.io/npm/v/mocha.svg" alt="NPM Version"></a>
|
|
10
10
|
<a href="https://github.com/mochajs/mocha"><img src="https://img.shields.io/node/v/mocha.svg" alt="Node Version"></a>
|
|
11
11
|
[](https://github.com/mochajs/mocha/actions/workflows/mocha.yml)
|
|
12
|
-
<a href="https://
|
|
12
|
+
<a href="https://codecov.io/gh/mochajs/mocha"><img src="https://codecov.io/gh/mochajs/mocha/branch/main/graph/badge.svg" alt="Codecov Coverage Status"></a>
|
|
13
13
|
|
|
14
14
|
</div>
|
|
15
15
|
|
package/bin/_mocha
CHANGED
package/bin/mocha.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
"use strict";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* This wrapper executable checks for known node flags and appends them when found,
|
|
@@ -10,16 +10,16 @@
|
|
|
10
10
|
* @private
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
const os = require(
|
|
14
|
-
const {loadOptions} = require(
|
|
13
|
+
const os = require("node:os");
|
|
14
|
+
const { loadOptions } = require("../lib/cli/options");
|
|
15
15
|
const {
|
|
16
16
|
unparseNodeFlags,
|
|
17
17
|
isNodeFlag,
|
|
18
|
-
impliesNoTimeouts
|
|
19
|
-
} = require(
|
|
20
|
-
const unparse = require(
|
|
21
|
-
const debug = require(
|
|
22
|
-
const {aliases} = require(
|
|
18
|
+
impliesNoTimeouts,
|
|
19
|
+
} = require("../lib/cli/node-flags");
|
|
20
|
+
const unparse = require("yargs-unparser");
|
|
21
|
+
const debug = require("debug")("mocha:cli:mocha");
|
|
22
|
+
const { aliases } = require("../lib/cli/run-option-metadata");
|
|
23
23
|
|
|
24
24
|
const mochaArgs = {};
|
|
25
25
|
const nodeArgs = {};
|
|
@@ -27,16 +27,16 @@ const SIGNAL_OFFSET = 128;
|
|
|
27
27
|
let hasInspect = false;
|
|
28
28
|
|
|
29
29
|
const opts = loadOptions(process.argv.slice(2));
|
|
30
|
-
debug(
|
|
30
|
+
debug("loaded opts", opts);
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Given option/command `value`, disable timeouts if applicable
|
|
34
34
|
* @param {string} [value] - Value to check
|
|
35
35
|
* @ignore
|
|
36
36
|
*/
|
|
37
|
-
const disableTimeouts = value => {
|
|
37
|
+
const disableTimeouts = (value) => {
|
|
38
38
|
if (impliesNoTimeouts(value)) {
|
|
39
|
-
debug(
|
|
39
|
+
debug("option %s disabled timeouts", value);
|
|
40
40
|
mochaArgs.timeout = 0;
|
|
41
41
|
}
|
|
42
42
|
};
|
|
@@ -47,11 +47,11 @@ const disableTimeouts = value => {
|
|
|
47
47
|
* @returns {string} `value` with prefix (maybe) removed
|
|
48
48
|
* @ignore
|
|
49
49
|
*/
|
|
50
|
-
const trimV8Option = value =>
|
|
51
|
-
value !==
|
|
50
|
+
const trimV8Option = (value) =>
|
|
51
|
+
value !== "v8-options" && /^v8-/.test(value) ? value.slice(3) : value;
|
|
52
52
|
|
|
53
53
|
// sort options into "node" and "mocha" buckets
|
|
54
|
-
Object.keys(opts).forEach(opt => {
|
|
54
|
+
Object.keys(opts).forEach((opt) => {
|
|
55
55
|
if (isNodeFlag(opt)) {
|
|
56
56
|
nodeArgs[trimV8Option(opt)] = opts[opt];
|
|
57
57
|
} else {
|
|
@@ -60,9 +60,9 @@ Object.keys(opts).forEach(opt => {
|
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
// disable 'timeout' for debugFlags
|
|
63
|
-
Object.keys(nodeArgs).forEach(opt => disableTimeouts(opt));
|
|
64
|
-
mochaArgs[
|
|
65
|
-
mochaArgs[
|
|
63
|
+
Object.keys(nodeArgs).forEach((opt) => disableTimeouts(opt));
|
|
64
|
+
mochaArgs["node-option"] &&
|
|
65
|
+
mochaArgs["node-option"].forEach((opt) => disableTimeouts(opt));
|
|
66
66
|
|
|
67
67
|
// Native debugger handling
|
|
68
68
|
// see https://nodejs.org/api/debugger.html#debugger_debugger
|
|
@@ -71,78 +71,80 @@ mochaArgs['node-option'] &&
|
|
|
71
71
|
// A deprecation warning will be printed by node, if applicable.
|
|
72
72
|
// (mochaArgs._ are "positional" arguments, not prefixed with - or --)
|
|
73
73
|
if (mochaArgs._) {
|
|
74
|
-
const i = mochaArgs._.findIndex(val => val ===
|
|
74
|
+
const i = mochaArgs._.findIndex((val) => val === "inspect");
|
|
75
75
|
if (i > -1) {
|
|
76
76
|
mochaArgs._.splice(i, 1);
|
|
77
|
-
disableTimeouts(
|
|
77
|
+
disableTimeouts("inspect");
|
|
78
78
|
hasInspect = true;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
if (mochaArgs[
|
|
83
|
-
const {spawn} = require(
|
|
84
|
-
const mochaPath = require.resolve(
|
|
82
|
+
if (mochaArgs["node-option"] || Object.keys(nodeArgs).length || hasInspect) {
|
|
83
|
+
const { spawn } = require("node:child_process");
|
|
84
|
+
const mochaPath = require.resolve("../lib/cli/cli.js");
|
|
85
85
|
|
|
86
86
|
const nodeArgv =
|
|
87
|
-
(mochaArgs[
|
|
87
|
+
(mochaArgs["node-option"] &&
|
|
88
|
+
mochaArgs["node-option"].map((v) => "--" + v)) ||
|
|
88
89
|
unparseNodeFlags(nodeArgs);
|
|
89
90
|
|
|
90
|
-
if (hasInspect) nodeArgv.unshift(
|
|
91
|
-
delete mochaArgs[
|
|
91
|
+
if (hasInspect) nodeArgv.unshift("inspect");
|
|
92
|
+
delete mochaArgs["node-option"];
|
|
92
93
|
|
|
93
|
-
debug(
|
|
94
|
+
debug("final node argv", nodeArgv);
|
|
94
95
|
|
|
95
96
|
const args = [].concat(
|
|
96
97
|
nodeArgv,
|
|
97
98
|
mochaPath,
|
|
98
|
-
unparse(mochaArgs, {alias: aliases})
|
|
99
|
+
unparse(mochaArgs, { alias: aliases }),
|
|
99
100
|
);
|
|
100
101
|
|
|
101
102
|
debug(
|
|
102
|
-
|
|
103
|
+
"forking child process via command: %s %s",
|
|
103
104
|
process.execPath,
|
|
104
|
-
args.join(
|
|
105
|
+
args.join(" "),
|
|
105
106
|
);
|
|
106
107
|
|
|
107
108
|
const proc = spawn(process.execPath, args, {
|
|
108
|
-
stdio:
|
|
109
|
+
stdio: "inherit",
|
|
109
110
|
});
|
|
110
111
|
|
|
111
|
-
proc.on(
|
|
112
|
-
process.on(
|
|
112
|
+
proc.on("exit", (code, signal) => {
|
|
113
|
+
process.on("exit", () => {
|
|
113
114
|
if (signal) {
|
|
114
|
-
signal =
|
|
115
|
-
|
|
115
|
+
signal =
|
|
116
|
+
typeof signal === "string" ? os.constants.signals[signal] : signal;
|
|
117
|
+
if (mochaArgs["posix-exit-codes"] === true) {
|
|
116
118
|
process.exitCode = SIGNAL_OFFSET + signal;
|
|
117
119
|
}
|
|
118
120
|
process.kill(process.pid, signal);
|
|
119
121
|
} else {
|
|
120
|
-
process.exit(Math.min(code, mochaArgs[
|
|
122
|
+
process.exit(Math.min(code, mochaArgs["posix-exit-codes"] ? 1 : 255));
|
|
121
123
|
}
|
|
122
124
|
});
|
|
123
125
|
});
|
|
124
126
|
|
|
125
127
|
// terminate children.
|
|
126
|
-
process.on(
|
|
128
|
+
process.on("SIGINT", () => {
|
|
127
129
|
// XXX: a previous comment said this would abort the runner, but I can't see that it does
|
|
128
130
|
// anything with the default runner.
|
|
129
|
-
debug(
|
|
130
|
-
proc.kill(
|
|
131
|
+
debug("main process caught SIGINT");
|
|
132
|
+
proc.kill("SIGINT");
|
|
131
133
|
// if running in parallel mode, we will have a proper SIGINT handler, so the below won't
|
|
132
134
|
// be needed.
|
|
133
135
|
if (!args.parallel || args.jobs < 2) {
|
|
134
136
|
// win32 does not support SIGTERM, so use next best thing.
|
|
135
|
-
if (os.platform() ===
|
|
136
|
-
proc.kill(
|
|
137
|
+
if (os.platform() === "win32") {
|
|
138
|
+
proc.kill("SIGKILL");
|
|
137
139
|
} else {
|
|
138
140
|
// using SIGKILL won't cleanly close the output streams, which can result
|
|
139
141
|
// in cut-off text or a befouled terminal.
|
|
140
|
-
debug(
|
|
141
|
-
proc.kill(
|
|
142
|
+
debug("sending SIGTERM to child process");
|
|
143
|
+
proc.kill("SIGTERM");
|
|
142
144
|
}
|
|
143
145
|
}
|
|
144
146
|
});
|
|
145
147
|
} else {
|
|
146
|
-
debug(
|
|
147
|
-
require(
|
|
148
|
+
debug("running Mocha in-process");
|
|
149
|
+
require("../lib/cli/cli").main([], mochaArgs);
|
|
148
150
|
}
|
package/browser-entry.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
/* eslint no-unused-vars: off */
|
|
4
4
|
/* eslint-env commonjs */
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
* Shim process.stdout.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
process.stdout = require(
|
|
10
|
+
process.stdout = require("browser-stdout")({ label: false });
|
|
11
11
|
|
|
12
|
-
var parseQuery = require(
|
|
13
|
-
var highlightTags = require(
|
|
14
|
-
var Mocha = require(
|
|
12
|
+
var parseQuery = require("./lib/browser/parse-query");
|
|
13
|
+
var highlightTags = require("./lib/browser/highlight-tags");
|
|
14
|
+
var Mocha = require("./lib/mocha");
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Create a Mocha instance.
|
|
@@ -19,7 +19,7 @@ var Mocha = require('./lib/mocha');
|
|
|
19
19
|
* @return {undefined}
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
var mocha = new Mocha({reporter:
|
|
22
|
+
var mocha = new Mocha({ reporter: "html" });
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Save timer references to avoid Sinon interfering (see GH-237).
|
|
@@ -41,7 +41,7 @@ var originalOnerrorHandler = global.onerror;
|
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
43
|
process.removeListener = function (e, fn) {
|
|
44
|
-
if (e ===
|
|
44
|
+
if (e === "uncaughtException") {
|
|
45
45
|
if (originalOnerrorHandler) {
|
|
46
46
|
global.onerror = originalOnerrorHandler;
|
|
47
47
|
} else {
|
|
@@ -59,7 +59,7 @@ process.removeListener = function (e, fn) {
|
|
|
59
59
|
*/
|
|
60
60
|
|
|
61
61
|
process.listenerCount = function (name) {
|
|
62
|
-
if (name ===
|
|
62
|
+
if (name === "uncaughtException") {
|
|
63
63
|
return uncaughtExceptionHandlers.length;
|
|
64
64
|
}
|
|
65
65
|
return 0;
|
|
@@ -70,9 +70,9 @@ process.listenerCount = function (name) {
|
|
|
70
70
|
*/
|
|
71
71
|
|
|
72
72
|
process.on = function (e, fn) {
|
|
73
|
-
if (e ===
|
|
73
|
+
if (e === "uncaughtException") {
|
|
74
74
|
global.onerror = function (msg, url, line, col, err) {
|
|
75
|
-
fn(err || new Error(msg +
|
|
75
|
+
fn(err || new Error(msg + " (" + url + ":" + line + ":" + col + ")"));
|
|
76
76
|
return !mocha.options.allowUncaught;
|
|
77
77
|
};
|
|
78
78
|
uncaughtExceptionHandlers.push(fn);
|
|
@@ -80,7 +80,7 @@ process.on = function (e, fn) {
|
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
process.listeners = function (err) {
|
|
83
|
-
if (err ===
|
|
83
|
+
if (err === "uncaughtException") {
|
|
84
84
|
return uncaughtExceptionHandlers;
|
|
85
85
|
}
|
|
86
86
|
return [];
|
|
@@ -89,7 +89,7 @@ process.listeners = function (err) {
|
|
|
89
89
|
// The BDD UI is registered by default, but no UI will be functional in the
|
|
90
90
|
// browser without an explicit call to the overridden `mocha.ui` (see below).
|
|
91
91
|
// Ensure that this default UI does not expose its methods to the global scope.
|
|
92
|
-
mocha.suite.removeAllListeners(
|
|
92
|
+
mocha.suite.removeAllListeners("pre-require");
|
|
93
93
|
|
|
94
94
|
var immediateQueue = [];
|
|
95
95
|
var immediateTimeout;
|
|
@@ -136,7 +136,7 @@ mocha.throwError = function (err) {
|
|
|
136
136
|
|
|
137
137
|
mocha.ui = function (ui) {
|
|
138
138
|
Mocha.prototype.ui.call(this, ui);
|
|
139
|
-
this.suite.emit(
|
|
139
|
+
this.suite.emit("pre-require", global, null, this);
|
|
140
140
|
return this;
|
|
141
141
|
};
|
|
142
142
|
|
|
@@ -145,8 +145,8 @@ mocha.ui = function (ui) {
|
|
|
145
145
|
*/
|
|
146
146
|
|
|
147
147
|
mocha.setup = function (opts) {
|
|
148
|
-
if (typeof opts ===
|
|
149
|
-
opts = {ui: opts};
|
|
148
|
+
if (typeof opts === "string") {
|
|
149
|
+
opts = { ui: opts };
|
|
150
150
|
}
|
|
151
151
|
if (opts.delay === true) {
|
|
152
152
|
this.delay();
|
|
@@ -154,7 +154,7 @@ mocha.setup = function (opts) {
|
|
|
154
154
|
var self = this;
|
|
155
155
|
Object.keys(opts)
|
|
156
156
|
.filter(function (opt) {
|
|
157
|
-
return opt !==
|
|
157
|
+
return opt !== "delay";
|
|
158
158
|
})
|
|
159
159
|
.forEach(function (opt) {
|
|
160
160
|
if (Object.prototype.hasOwnProperty.call(opts, opt)) {
|
|
@@ -170,9 +170,9 @@ mocha.setup = function (opts) {
|
|
|
170
170
|
|
|
171
171
|
mocha.run = function (fn) {
|
|
172
172
|
var options = mocha.options;
|
|
173
|
-
mocha.globals(
|
|
173
|
+
mocha.globals("location");
|
|
174
174
|
|
|
175
|
-
var query = parseQuery(global.location.search ||
|
|
175
|
+
var query = parseQuery(global.location.search || "");
|
|
176
176
|
if (query.grep) {
|
|
177
177
|
mocha.grep(query.grep);
|
|
178
178
|
}
|
|
@@ -188,10 +188,10 @@ mocha.run = function (fn) {
|
|
|
188
188
|
var document = global.document;
|
|
189
189
|
if (
|
|
190
190
|
document &&
|
|
191
|
-
document.getElementById(
|
|
191
|
+
document.getElementById("mocha") &&
|
|
192
192
|
options.noHighlighting !== true
|
|
193
193
|
) {
|
|
194
|
-
highlightTags(
|
|
194
|
+
highlightTags("code");
|
|
195
195
|
}
|
|
196
196
|
if (fn) {
|
|
197
197
|
fn(err);
|
package/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
module.exports = require(
|
|
3
|
+
module.exports = require("./lib/mocha");
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Highlight the given string of `js`.
|
|
@@ -9,19 +9,19 @@
|
|
|
9
9
|
*/
|
|
10
10
|
function highlight(js) {
|
|
11
11
|
return js
|
|
12
|
-
.replace(/</g,
|
|
13
|
-
.replace(/>/g,
|
|
12
|
+
.replace(/</g, "<")
|
|
13
|
+
.replace(/>/g, ">")
|
|
14
14
|
.replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')
|
|
15
15
|
.replace(/('.*?')/gm, '<span class="string">$1</span>')
|
|
16
16
|
.replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
|
|
17
17
|
.replace(/(\d+)/gm, '<span class="number">$1</span>')
|
|
18
18
|
.replace(
|
|
19
19
|
/\bnew[ \t]+(\w+)/gm,
|
|
20
|
-
'<span class="keyword">new</span> <span class="init">$1</span>'
|
|
20
|
+
'<span class="keyword">new</span> <span class="init">$1</span>',
|
|
21
21
|
)
|
|
22
22
|
.replace(
|
|
23
23
|
/\b(function|new|throw|return|var|if|else)\b/gm,
|
|
24
|
-
'<span class="keyword">$1</span>'
|
|
24
|
+
'<span class="keyword">$1</span>',
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -32,7 +32,7 @@ function highlight(js) {
|
|
|
32
32
|
* @param {string} name
|
|
33
33
|
*/
|
|
34
34
|
module.exports = function highlightTags(name) {
|
|
35
|
-
var code = document.getElementById(
|
|
35
|
+
var code = document.getElementById("mocha").getElementsByTagName(name);
|
|
36
36
|
for (var i = 0, len = code.length; i < len; ++i) {
|
|
37
37
|
code[i].innerHTML = highlight(code[i].innerHTML);
|
|
38
38
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Parse the given `qs`.
|
|
@@ -9,15 +9,15 @@
|
|
|
9
9
|
*/
|
|
10
10
|
module.exports = function parseQuery(qs) {
|
|
11
11
|
return qs
|
|
12
|
-
.replace(
|
|
13
|
-
.split(
|
|
12
|
+
.replace("?", "")
|
|
13
|
+
.split("&")
|
|
14
14
|
.reduce(function (obj, pair) {
|
|
15
|
-
var i = pair.indexOf(
|
|
15
|
+
var i = pair.indexOf("=");
|
|
16
16
|
var key = pair.slice(0, i);
|
|
17
17
|
var val = pair.slice(++i);
|
|
18
18
|
|
|
19
19
|
// Due to how the URLSearchParams API treats spaces
|
|
20
|
-
obj[key] = decodeURIComponent(val.replace(/\+/g,
|
|
20
|
+
obj[key] = decodeURIComponent(val.replace(/\+/g, "%20"));
|
|
21
21
|
|
|
22
22
|
return obj;
|
|
23
23
|
}, {});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<!
|
|
1
|
+
<!doctype html>
|
|
2
2
|
<html lang="en">
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="utf-8" />
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<div id="mocha"></div>
|
|
11
11
|
<script src="mocha.js"></script>
|
|
12
12
|
<script>
|
|
13
|
-
mocha.setup(
|
|
13
|
+
mocha.setup("bdd");
|
|
14
14
|
</script>
|
|
15
15
|
<script src="tests.spec.js"></script>
|
|
16
16
|
<script>
|
package/lib/cli/cli.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Contains CLI entry point and public API for programmatic usage in Node.js.
|
|
@@ -8,21 +8,26 @@
|
|
|
8
8
|
* @module lib/cli
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
const debug = require(
|
|
12
|
-
const symbols = require(
|
|
13
|
-
const yargs = require(
|
|
14
|
-
const path = require(
|
|
11
|
+
const debug = require("debug")("mocha:cli:cli");
|
|
12
|
+
const symbols = require("log-symbols");
|
|
13
|
+
const yargs = require("yargs");
|
|
14
|
+
const path = require("node:path");
|
|
15
15
|
const {
|
|
16
16
|
loadRc,
|
|
17
17
|
loadPkgRc,
|
|
18
18
|
loadOptions,
|
|
19
|
-
YARGS_PARSER_CONFIG
|
|
20
|
-
} = require(
|
|
21
|
-
const lookupFiles = require(
|
|
22
|
-
const commands = require(
|
|
23
|
-
const pc = require(
|
|
24
|
-
const {
|
|
25
|
-
|
|
19
|
+
YARGS_PARSER_CONFIG,
|
|
20
|
+
} = require("./options");
|
|
21
|
+
const lookupFiles = require("./lookup-files");
|
|
22
|
+
const commands = require("./commands");
|
|
23
|
+
const pc = require("picocolors");
|
|
24
|
+
const {
|
|
25
|
+
repository,
|
|
26
|
+
homepage,
|
|
27
|
+
version,
|
|
28
|
+
discord,
|
|
29
|
+
} = require("../../package.json");
|
|
30
|
+
const { cwd } = require("../utils");
|
|
26
31
|
|
|
27
32
|
/**
|
|
28
33
|
* - Accepts an `Array` of arguments
|
|
@@ -34,46 +39,46 @@ const {cwd} = require('../utils');
|
|
|
34
39
|
* @param {object} [mochaArgs] - Object of already parsed Mocha arguments (by bin/mocha)
|
|
35
40
|
*/
|
|
36
41
|
exports.main = (argv = process.argv.slice(2), mochaArgs) => {
|
|
37
|
-
debug(
|
|
42
|
+
debug("entered main with raw args", argv);
|
|
38
43
|
// ensure we can require() from current working directory
|
|
39
|
-
if (typeof module.paths !==
|
|
40
|
-
module.paths.push(cwd(), path.resolve(
|
|
44
|
+
if (typeof module.paths !== "undefined") {
|
|
45
|
+
module.paths.push(cwd(), path.resolve("node_modules"));
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
try {
|
|
44
49
|
Error.stackTraceLimit = Infinity; // configurable via --stack-trace-limit?
|
|
45
50
|
} catch (err) {
|
|
46
|
-
debug(
|
|
51
|
+
debug("unable to set Error.stackTraceLimit = Infinity", err);
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
var args = mochaArgs || loadOptions(argv);
|
|
50
55
|
|
|
51
56
|
yargs()
|
|
52
|
-
.scriptName(
|
|
57
|
+
.scriptName("mocha")
|
|
53
58
|
.command(commands.run)
|
|
54
59
|
.command(commands.init)
|
|
55
60
|
.updateStrings({
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
"Positionals:": "Positional Arguments",
|
|
62
|
+
"Options:": "Other Options",
|
|
63
|
+
"Commands:": "Commands",
|
|
59
64
|
})
|
|
60
65
|
.fail((msg, err, yargs) => {
|
|
61
|
-
debug(
|
|
66
|
+
debug("caught error sometime before command handler: %O", err);
|
|
62
67
|
yargs.showHelp();
|
|
63
|
-
console.error(`\n${symbols.error} ${pc.red(
|
|
68
|
+
console.error(`\n${symbols.error} ${pc.red("ERROR:")} ${msg}`);
|
|
64
69
|
process.exit(1);
|
|
65
70
|
})
|
|
66
|
-
.help(
|
|
67
|
-
.alias(
|
|
68
|
-
.version(
|
|
69
|
-
.alias(
|
|
71
|
+
.help("help", "Show usage information & exit")
|
|
72
|
+
.alias("help", "h")
|
|
73
|
+
.version("version", "Show version number & exit", version)
|
|
74
|
+
.alias("version", "V")
|
|
70
75
|
.wrap(process.stdout.columns ? Math.min(process.stdout.columns, 80) : 80)
|
|
71
76
|
.epilog(
|
|
72
77
|
`${pc.reset("Mocha Resources")}
|
|
73
78
|
Chat: ${pc.magenta(discord)}
|
|
74
79
|
GitHub: ${pc.blue(repository.url)}
|
|
75
80
|
Docs: ${pc.yellow(homepage)}
|
|
76
|
-
|
|
81
|
+
`,
|
|
77
82
|
)
|
|
78
83
|
.parserConfiguration(YARGS_PARSER_CONFIG)
|
|
79
84
|
.config(args)
|
package/lib/cli/collect-files.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
const path = require(
|
|
4
|
-
const pc = require(
|
|
5
|
-
const debug = require(
|
|
6
|
-
const { minimatch } = require(
|
|
7
|
-
const {NO_FILES_MATCH_PATTERN} = require(
|
|
8
|
-
const lookupFiles = require(
|
|
9
|
-
const {castArray} = require(
|
|
3
|
+
const path = require("node:path");
|
|
4
|
+
const pc = require("picocolors");
|
|
5
|
+
const debug = require("debug")("mocha:cli:run:helpers");
|
|
6
|
+
const { minimatch } = require("minimatch");
|
|
7
|
+
const { NO_FILES_MATCH_PATTERN } = require("../error-constants").constants;
|
|
8
|
+
const lookupFiles = require("./lookup-files");
|
|
9
|
+
const { castArray } = require("../utils");
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Exports a function that collects test files from CLI parameters.
|
|
@@ -33,23 +33,23 @@ module.exports = ({
|
|
|
33
33
|
file: fileArgs,
|
|
34
34
|
recursive,
|
|
35
35
|
sort,
|
|
36
|
-
spec
|
|
36
|
+
spec,
|
|
37
37
|
} = {}) => {
|
|
38
38
|
const unmatchedSpecFiles = [];
|
|
39
39
|
const specFiles = spec.reduce((specFiles, arg) => {
|
|
40
40
|
try {
|
|
41
41
|
const moreSpecFiles = castArray(lookupFiles(arg, extension, recursive))
|
|
42
|
-
.filter(filename =>
|
|
42
|
+
.filter((filename) =>
|
|
43
43
|
ignore.every(
|
|
44
|
-
pattern =>
|
|
45
|
-
!minimatch(filename, pattern, {windowsPathsNoEscape: true})
|
|
46
|
-
)
|
|
44
|
+
(pattern) =>
|
|
45
|
+
!minimatch(filename, pattern, { windowsPathsNoEscape: true }),
|
|
46
|
+
),
|
|
47
47
|
)
|
|
48
|
-
.map(filename => path.resolve(filename));
|
|
48
|
+
.map((filename) => path.resolve(filename));
|
|
49
49
|
return [...specFiles, ...moreSpecFiles];
|
|
50
50
|
} catch (err) {
|
|
51
51
|
if (err.code === NO_FILES_MATCH_PATTERN) {
|
|
52
|
-
unmatchedSpecFiles.push({message: err.message, pattern: err.pattern});
|
|
52
|
+
unmatchedSpecFiles.push({ message: err.message, pattern: err.pattern });
|
|
53
53
|
return specFiles;
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -60,16 +60,16 @@ module.exports = ({
|
|
|
60
60
|
// check that each file passed in to --file exists
|
|
61
61
|
|
|
62
62
|
const unmatchedFiles = [];
|
|
63
|
-
fileArgs.forEach(file => {
|
|
63
|
+
fileArgs.forEach((file) => {
|
|
64
64
|
const fileAbsolutePath = path.resolve(file);
|
|
65
65
|
try {
|
|
66
66
|
// Used instead of fs.existsSync to ensure that file-ending less files are still resolved correctly
|
|
67
67
|
require.resolve(fileAbsolutePath);
|
|
68
68
|
} catch (err) {
|
|
69
|
-
if (err.code ===
|
|
69
|
+
if (err.code === "MODULE_NOT_FOUND") {
|
|
70
70
|
unmatchedFiles.push({
|
|
71
71
|
pattern: file,
|
|
72
|
-
absolutePath: fileAbsolutePath
|
|
72
|
+
absolutePath: fileAbsolutePath,
|
|
73
73
|
});
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
@@ -85,30 +85,30 @@ module.exports = ({
|
|
|
85
85
|
|
|
86
86
|
// add files given through --file to be ran first
|
|
87
87
|
const files = [
|
|
88
|
-
...fileArgs.map(filepath => path.resolve(filepath)),
|
|
89
|
-
...specFiles
|
|
88
|
+
...fileArgs.map((filepath) => path.resolve(filepath)),
|
|
89
|
+
...specFiles,
|
|
90
90
|
];
|
|
91
|
-
debug(
|
|
91
|
+
debug("test files (in order): ", files);
|
|
92
92
|
|
|
93
93
|
if (!files.length) {
|
|
94
94
|
// give full message details when only 1 file is missing
|
|
95
95
|
const noneFoundMsg =
|
|
96
96
|
unmatchedSpecFiles.length === 1
|
|
97
97
|
? `Error: No test files found: ${JSON.stringify(
|
|
98
|
-
unmatchedSpecFiles[0].pattern
|
|
98
|
+
unmatchedSpecFiles[0].pattern,
|
|
99
99
|
)}` // stringify to print escaped characters raw
|
|
100
|
-
:
|
|
100
|
+
: "Error: No test files found";
|
|
101
101
|
console.error(pc.red(noneFoundMsg));
|
|
102
102
|
process.exit(1);
|
|
103
103
|
} else {
|
|
104
104
|
// print messages as a warning
|
|
105
|
-
unmatchedSpecFiles.forEach(warning => {
|
|
105
|
+
unmatchedSpecFiles.forEach((warning) => {
|
|
106
106
|
console.warn(pc.yellow(`Warning: ${warning.message}`));
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
return {
|
|
111
111
|
files,
|
|
112
|
-
unmatchedFiles
|
|
112
|
+
unmatchedFiles,
|
|
113
113
|
};
|
|
114
114
|
};
|
package/lib/cli/commands.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Exports Yargs commands
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
module.exports = {
|
|
11
|
-
init: require(
|
|
11
|
+
init: require("./init"),
|
|
12
12
|
// default command
|
|
13
|
-
run: require(
|
|
14
|
-
}
|
|
13
|
+
run: require("./run"),
|
|
14
|
+
};
|