mocha 11.7.5 → 12.0.0-alpha-issue-5899.2
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 +4 -4
- package/bin/_mocha +2 -2
- package/bin/mocha.js +46 -44
- package/browser-entry.js +20 -21
- package/index.js +2 -2
- package/lib/browser/{highlight-tags.js → highlight-tags.mjs} +7 -9
- package/lib/browser/{parse-query.js → parse-query.mjs} +7 -9
- package/lib/browser/template.html +2 -2
- package/lib/cli/cli.js +40 -27
- package/lib/cli/collect-files.js +25 -25
- package/lib/cli/{commands.js → commands.mjs} +3 -7
- package/lib/cli/config.js +31 -27
- package/lib/cli/index.js +2 -2
- package/lib/cli/init.mjs +34 -0
- package/lib/cli/{lookup-files.js → lookup-files.mjs} +27 -30
- package/lib/cli/{node-flags.js → node-flags.mjs} +16 -16
- package/lib/cli/{one-and-dones.js → one-and-dones.mjs} +15 -14
- package/lib/cli/{options.js → options.mjs} +59 -66
- package/lib/cli/run-helpers.js +52 -54
- package/lib/cli/run-option-metadata.mjs +138 -0
- package/lib/cli/run.js +168 -171
- package/lib/cli/watch-run.js +75 -75
- package/lib/context.mjs +79 -0
- package/lib/{error-constants.js → error-constants.mjs} +17 -21
- package/lib/{errors.js → errors.mjs} +33 -93
- package/lib/hook.mjs +80 -0
- package/lib/interfaces/{bdd.js → bdd.mjs} +14 -15
- package/lib/interfaces/{common.js → common.mjs} +19 -27
- package/lib/interfaces/{exports.js → exports.mjs} +13 -11
- package/lib/interfaces/index.mjs +11 -0
- package/lib/interfaces/{qunit.js → qunit.mjs} +13 -13
- package/lib/interfaces/{tdd.js → tdd.mjs} +14 -15
- package/lib/mocha.js +126 -100
- package/lib/nodejs/buffered-worker-pool.js +30 -30
- package/lib/nodejs/esm-utils.js +45 -22
- package/lib/nodejs/file-unloader.js +2 -2
- package/lib/nodejs/parallel-buffered-runner.js +68 -69
- package/lib/nodejs/reporters/parallel-buffered.js +13 -10
- package/lib/nodejs/serializer.js +47 -47
- package/lib/nodejs/worker.js +39 -40
- package/lib/pending.mjs +17 -0
- package/lib/{plugin-loader.js → plugin-loader.mjs} +50 -51
- package/lib/reporters/base.js +192 -192
- package/lib/reporters/doc.mjs +100 -0
- package/lib/reporters/dot.mjs +77 -0
- package/lib/reporters/html.mjs +424 -0
- package/lib/reporters/index.js +30 -16
- package/lib/reporters/json-stream.mjs +89 -0
- package/lib/reporters/json.mjs +164 -0
- package/lib/reporters/landing.mjs +112 -0
- package/lib/reporters/list.mjs +73 -0
- package/lib/reporters/markdown.mjs +113 -0
- package/lib/reporters/min.mjs +48 -0
- package/lib/reporters/nyan.mjs +262 -0
- package/lib/reporters/progress.mjs +101 -0
- package/lib/reporters/spec.mjs +94 -0
- package/lib/reporters/tap.mjs +275 -0
- package/lib/reporters/xunit.mjs +227 -0
- package/lib/runnable.mjs +475 -0
- package/lib/runner.js +228 -111
- package/lib/{stats-collector.js → stats-collector.mjs} +13 -14
- package/lib/suite.mjs +670 -0
- package/lib/test.mjs +107 -0
- package/lib/utils/regexp.mjs +14 -0
- package/lib/utils.js +150 -144
- package/mocha.css +68 -50
- package/mocha.js +18579 -21600
- package/mocha.js.map +1 -1
- package/mocha.mjs +67 -0
- package/package.json +53 -84
- package/lib/cli/init.js +0 -36
- package/lib/cli/run-option-metadata.js +0 -138
- package/lib/context.js +0 -91
- package/lib/hook.js +0 -89
- package/lib/interfaces/index.js +0 -6
- package/lib/pending.js +0 -16
- package/lib/reporters/doc.js +0 -100
- package/lib/reporters/dot.js +0 -86
- package/lib/reporters/html.js +0 -423
- package/lib/reporters/json-stream.js +0 -93
- package/lib/reporters/json.js +0 -167
- package/lib/reporters/landing.js +0 -121
- package/lib/reporters/list.js +0 -83
- package/lib/reporters/markdown.js +0 -117
- package/lib/reporters/min.js +0 -57
- package/lib/reporters/nyan.js +0 -272
- package/lib/reporters/progress.js +0 -109
- package/lib/reporters/spec.js +0 -105
- package/lib/reporters/tap.js +0 -298
- package/lib/reporters/xunit.js +0 -232
- package/lib/runnable.js +0 -476
- package/lib/suite.js +0 -670
- package/lib/test.js +0 -113
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="
|
|
2
|
+
<img src="docs/src/components/mocha-logo.svg" alt="Mocha test framework logo"/>
|
|
3
3
|
</p>
|
|
4
4
|
|
|
5
|
-
<p align="center">☕️
|
|
5
|
+
<p align="center">☕️ Classic, reliable, trusted test framework for Node.js and the browser ☕️</p>
|
|
6
6
|
|
|
7
7
|
<div align="center">
|
|
8
8
|
|
|
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
|
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
|
|
37
37
|
[Become a backer](https://opencollective.com/mochajs) and show your support to our open source project on [our site](https://mochajs.org/#backers).
|
|
38
38
|
|
|
39
|
-
<a href="https://opencollective.com/mochajs"><img src="https://opencollective.com/mochajs/tiers/backers.svg?limit=30&button=false&avatarHeight=46&width=750"></a>
|
|
39
|
+
<a href="https://opencollective.com/mochajs"><img alt="Mocha's backers on Open Collective" src="https://opencollective.com/mochajs/tiers/backers.svg?limit=30&button=false&avatarHeight=46&width=750"></a>
|
|
40
40
|
|
|
41
41
|
## Sponsors
|
|
42
42
|
|
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.mjs");
|
|
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.mjs");
|
|
20
|
+
const unparse = require("yargs-unparser");
|
|
21
|
+
const debug = require("debug")("mocha:cli:mocha");
|
|
22
|
+
const { aliases } = require("../lib/cli/run-option-metadata.mjs");
|
|
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,17 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
3
|
/* eslint no-unused-vars: off */
|
|
4
|
-
/* eslint-env commonjs */
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Shim process.stdout.
|
|
8
7
|
*/
|
|
9
8
|
|
|
10
|
-
process.stdout = require(
|
|
9
|
+
process.stdout = require("browser-stdout")({ label: false });
|
|
11
10
|
|
|
12
|
-
var parseQuery = require(
|
|
13
|
-
var highlightTags = require(
|
|
14
|
-
var Mocha = require(
|
|
11
|
+
var parseQuery = require("./lib/browser/parse-query.mjs").parseQuery;
|
|
12
|
+
var highlightTags = require("./lib/browser/highlight-tags.mjs").highlightTags;
|
|
13
|
+
var Mocha = require("./lib/mocha");
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* Create a Mocha instance.
|
|
@@ -19,7 +18,7 @@ var Mocha = require('./lib/mocha');
|
|
|
19
18
|
* @return {undefined}
|
|
20
19
|
*/
|
|
21
20
|
|
|
22
|
-
var mocha = new Mocha({reporter:
|
|
21
|
+
var mocha = new Mocha({ reporter: "html" });
|
|
23
22
|
|
|
24
23
|
/**
|
|
25
24
|
* Save timer references to avoid Sinon interfering (see GH-237).
|
|
@@ -41,7 +40,7 @@ var originalOnerrorHandler = global.onerror;
|
|
|
41
40
|
*/
|
|
42
41
|
|
|
43
42
|
process.removeListener = function (e, fn) {
|
|
44
|
-
if (e ===
|
|
43
|
+
if (e === "uncaughtException") {
|
|
45
44
|
if (originalOnerrorHandler) {
|
|
46
45
|
global.onerror = originalOnerrorHandler;
|
|
47
46
|
} else {
|
|
@@ -59,7 +58,7 @@ process.removeListener = function (e, fn) {
|
|
|
59
58
|
*/
|
|
60
59
|
|
|
61
60
|
process.listenerCount = function (name) {
|
|
62
|
-
if (name ===
|
|
61
|
+
if (name === "uncaughtException") {
|
|
63
62
|
return uncaughtExceptionHandlers.length;
|
|
64
63
|
}
|
|
65
64
|
return 0;
|
|
@@ -70,9 +69,9 @@ process.listenerCount = function (name) {
|
|
|
70
69
|
*/
|
|
71
70
|
|
|
72
71
|
process.on = function (e, fn) {
|
|
73
|
-
if (e ===
|
|
72
|
+
if (e === "uncaughtException") {
|
|
74
73
|
global.onerror = function (msg, url, line, col, err) {
|
|
75
|
-
fn(err || new Error(msg +
|
|
74
|
+
fn(err || new Error(msg + " (" + url + ":" + line + ":" + col + ")"));
|
|
76
75
|
return !mocha.options.allowUncaught;
|
|
77
76
|
};
|
|
78
77
|
uncaughtExceptionHandlers.push(fn);
|
|
@@ -80,7 +79,7 @@ process.on = function (e, fn) {
|
|
|
80
79
|
};
|
|
81
80
|
|
|
82
81
|
process.listeners = function (err) {
|
|
83
|
-
if (err ===
|
|
82
|
+
if (err === "uncaughtException") {
|
|
84
83
|
return uncaughtExceptionHandlers;
|
|
85
84
|
}
|
|
86
85
|
return [];
|
|
@@ -89,7 +88,7 @@ process.listeners = function (err) {
|
|
|
89
88
|
// The BDD UI is registered by default, but no UI will be functional in the
|
|
90
89
|
// browser without an explicit call to the overridden `mocha.ui` (see below).
|
|
91
90
|
// Ensure that this default UI does not expose its methods to the global scope.
|
|
92
|
-
mocha.suite.removeAllListeners(
|
|
91
|
+
mocha.suite.removeAllListeners("pre-require");
|
|
93
92
|
|
|
94
93
|
var immediateQueue = [];
|
|
95
94
|
var immediateTimeout;
|
|
@@ -136,7 +135,7 @@ mocha.throwError = function (err) {
|
|
|
136
135
|
|
|
137
136
|
mocha.ui = function (ui) {
|
|
138
137
|
Mocha.prototype.ui.call(this, ui);
|
|
139
|
-
this.suite.emit(
|
|
138
|
+
this.suite.emit("pre-require", global, null, this);
|
|
140
139
|
return this;
|
|
141
140
|
};
|
|
142
141
|
|
|
@@ -145,8 +144,8 @@ mocha.ui = function (ui) {
|
|
|
145
144
|
*/
|
|
146
145
|
|
|
147
146
|
mocha.setup = function (opts) {
|
|
148
|
-
if (typeof opts ===
|
|
149
|
-
opts = {ui: opts};
|
|
147
|
+
if (typeof opts === "string") {
|
|
148
|
+
opts = { ui: opts };
|
|
150
149
|
}
|
|
151
150
|
if (opts.delay === true) {
|
|
152
151
|
this.delay();
|
|
@@ -154,7 +153,7 @@ mocha.setup = function (opts) {
|
|
|
154
153
|
var self = this;
|
|
155
154
|
Object.keys(opts)
|
|
156
155
|
.filter(function (opt) {
|
|
157
|
-
return opt !==
|
|
156
|
+
return opt !== "delay";
|
|
158
157
|
})
|
|
159
158
|
.forEach(function (opt) {
|
|
160
159
|
if (Object.prototype.hasOwnProperty.call(opts, opt)) {
|
|
@@ -170,9 +169,9 @@ mocha.setup = function (opts) {
|
|
|
170
169
|
|
|
171
170
|
mocha.run = function (fn) {
|
|
172
171
|
var options = mocha.options;
|
|
173
|
-
mocha.globals(
|
|
172
|
+
mocha.globals("location");
|
|
174
173
|
|
|
175
|
-
var query = parseQuery(global.location.search ||
|
|
174
|
+
var query = parseQuery(global.location.search || "");
|
|
176
175
|
if (query.grep) {
|
|
177
176
|
mocha.grep(query.grep);
|
|
178
177
|
}
|
|
@@ -188,10 +187,10 @@ mocha.run = function (fn) {
|
|
|
188
187
|
var document = global.document;
|
|
189
188
|
if (
|
|
190
189
|
document &&
|
|
191
|
-
document.getElementById(
|
|
190
|
+
document.getElementById("mocha") &&
|
|
192
191
|
options.noHighlighting !== true
|
|
193
192
|
) {
|
|
194
|
-
highlightTags(
|
|
193
|
+
highlightTags("code");
|
|
195
194
|
}
|
|
196
195
|
if (fn) {
|
|
197
196
|
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,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Highlight the given string of `js`.
|
|
5
3
|
*
|
|
@@ -9,19 +7,19 @@
|
|
|
9
7
|
*/
|
|
10
8
|
function highlight(js) {
|
|
11
9
|
return js
|
|
12
|
-
.replace(/</g,
|
|
13
|
-
.replace(/>/g,
|
|
10
|
+
.replace(/</g, "<")
|
|
11
|
+
.replace(/>/g, ">")
|
|
14
12
|
.replace(/\/\/(.*)/gm, '<span class="comment">//$1</span>')
|
|
15
13
|
.replace(/('.*?')/gm, '<span class="string">$1</span>')
|
|
16
14
|
.replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
|
|
17
15
|
.replace(/(\d+)/gm, '<span class="number">$1</span>')
|
|
18
16
|
.replace(
|
|
19
17
|
/\bnew[ \t]+(\w+)/gm,
|
|
20
|
-
'<span class="keyword">new</span> <span class="init">$1</span>'
|
|
18
|
+
'<span class="keyword">new</span> <span class="init">$1</span>',
|
|
21
19
|
)
|
|
22
20
|
.replace(
|
|
23
21
|
/\b(function|new|throw|return|var|if|else)\b/gm,
|
|
24
|
-
'<span class="keyword">$1</span>'
|
|
22
|
+
'<span class="keyword">$1</span>',
|
|
25
23
|
);
|
|
26
24
|
}
|
|
27
25
|
|
|
@@ -31,9 +29,9 @@ function highlight(js) {
|
|
|
31
29
|
* @private
|
|
32
30
|
* @param {string} name
|
|
33
31
|
*/
|
|
34
|
-
|
|
35
|
-
var code = document.getElementById(
|
|
32
|
+
export function highlightTags(name) {
|
|
33
|
+
var code = document.getElementById("mocha").getElementsByTagName(name);
|
|
36
34
|
for (var i = 0, len = code.length; i < len; ++i) {
|
|
37
35
|
code[i].innerHTML = highlight(code[i].innerHTML);
|
|
38
36
|
}
|
|
39
|
-
}
|
|
37
|
+
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Parse the given `qs`.
|
|
5
3
|
*
|
|
@@ -7,18 +5,18 @@
|
|
|
7
5
|
* @param {string} qs
|
|
8
6
|
* @return {Object<string, string>}
|
|
9
7
|
*/
|
|
10
|
-
|
|
8
|
+
export function parseQuery(qs) {
|
|
11
9
|
return qs
|
|
12
|
-
.replace(
|
|
13
|
-
.split(
|
|
10
|
+
.replace("?", "")
|
|
11
|
+
.split("&")
|
|
14
12
|
.reduce(function (obj, pair) {
|
|
15
|
-
var i = pair.indexOf(
|
|
13
|
+
var i = pair.indexOf("=");
|
|
16
14
|
var key = pair.slice(0, i);
|
|
17
|
-
var val = pair.slice(
|
|
15
|
+
var val = pair.slice(i + 1);
|
|
18
16
|
|
|
19
17
|
// Due to how the URLSearchParams API treats spaces
|
|
20
|
-
obj[key] = decodeURIComponent(val.replace(/\+/g,
|
|
18
|
+
obj[key] = decodeURIComponent(val.replace(/\+/g, "%20"));
|
|
21
19
|
|
|
22
20
|
return obj;
|
|
23
21
|
}, {});
|
|
24
|
-
}
|
|
22
|
+
}
|
|
@@ -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,25 @@
|
|
|
8
8
|
* @module lib/cli
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
const debug = require(
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const path = require('node:path');
|
|
11
|
+
const debug = require("debug")("mocha:cli:cli");
|
|
12
|
+
const yargs = require("yargs");
|
|
13
|
+
const path = require("node:path");
|
|
15
14
|
const {
|
|
16
15
|
loadRc,
|
|
17
16
|
loadPkgRc,
|
|
18
17
|
loadOptions,
|
|
19
|
-
YARGS_PARSER_CONFIG
|
|
20
|
-
} = require(
|
|
21
|
-
const lookupFiles = require(
|
|
22
|
-
const commands = require(
|
|
23
|
-
const pc = require(
|
|
24
|
-
const {
|
|
25
|
-
|
|
18
|
+
YARGS_PARSER_CONFIG,
|
|
19
|
+
} = require("./options.mjs");
|
|
20
|
+
const { lookupFiles } = require("./lookup-files.mjs");
|
|
21
|
+
const commands = require("./commands.mjs");
|
|
22
|
+
const pc = require("picocolors");
|
|
23
|
+
const {
|
|
24
|
+
repository,
|
|
25
|
+
homepage,
|
|
26
|
+
version,
|
|
27
|
+
discord,
|
|
28
|
+
} = require("../../package.json");
|
|
29
|
+
const { cwd, logSymbols } = require("../utils");
|
|
26
30
|
|
|
27
31
|
/**
|
|
28
32
|
* - Accepts an `Array` of arguments
|
|
@@ -34,46 +38,55 @@ const {cwd} = require('../utils');
|
|
|
34
38
|
* @param {object} [mochaArgs] - Object of already parsed Mocha arguments (by bin/mocha)
|
|
35
39
|
*/
|
|
36
40
|
exports.main = (argv = process.argv.slice(2), mochaArgs) => {
|
|
37
|
-
debug(
|
|
41
|
+
debug("entered main with raw args", argv);
|
|
38
42
|
// ensure we can require() from current working directory
|
|
39
|
-
if (typeof module.paths !==
|
|
40
|
-
module.paths
|
|
43
|
+
if (typeof module.paths !== "undefined") {
|
|
44
|
+
debug("module.paths before modification", module.paths);
|
|
45
|
+
module.paths.push(cwd(), path.resolve("node_modules"));
|
|
46
|
+
debug("module.paths after modification", module.paths);
|
|
47
|
+
} else {
|
|
48
|
+
debug("module.paths is undefined");
|
|
41
49
|
}
|
|
42
50
|
|
|
43
51
|
try {
|
|
44
52
|
Error.stackTraceLimit = Infinity; // configurable via --stack-trace-limit?
|
|
45
53
|
} catch (err) {
|
|
46
|
-
debug(
|
|
54
|
+
debug("unable to set Error.stackTraceLimit = Infinity", err);
|
|
47
55
|
}
|
|
48
56
|
|
|
49
57
|
var args = mochaArgs || loadOptions(argv);
|
|
50
58
|
|
|
51
59
|
yargs()
|
|
52
|
-
.scriptName(
|
|
60
|
+
.scriptName("mocha")
|
|
53
61
|
.command(commands.run)
|
|
54
62
|
.command(commands.init)
|
|
55
63
|
.updateStrings({
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
"Positionals:": "Positional Arguments",
|
|
65
|
+
"Options:": "Other Options",
|
|
66
|
+
"Commands:": "Commands",
|
|
59
67
|
})
|
|
60
68
|
.fail((msg, err, yargs) => {
|
|
61
|
-
debug(
|
|
69
|
+
debug("caught error sometime before command handler: %O", err);
|
|
62
70
|
yargs.showHelp();
|
|
63
|
-
console.error(`\n${
|
|
71
|
+
console.error(`\n${logSymbols.error} ${pc.red("ERROR:")} ${msg}`);
|
|
72
|
+
if (!msg) {
|
|
73
|
+
// Log raw error and stack when an unexpected error is encountered, to
|
|
74
|
+
// make debugging easier (instead of an inactionable "ERROR: null").
|
|
75
|
+
console.error(err);
|
|
76
|
+
}
|
|
64
77
|
process.exit(1);
|
|
65
78
|
})
|
|
66
|
-
.help(
|
|
67
|
-
.alias(
|
|
68
|
-
.version(
|
|
69
|
-
.alias(
|
|
79
|
+
.help("help", "Show usage information & exit")
|
|
80
|
+
.alias("help", "h")
|
|
81
|
+
.version("version", "Show version number & exit", version)
|
|
82
|
+
.alias("version", "V")
|
|
70
83
|
.wrap(process.stdout.columns ? Math.min(process.stdout.columns, 80) : 80)
|
|
71
84
|
.epilog(
|
|
72
85
|
`${pc.reset("Mocha Resources")}
|
|
73
86
|
Chat: ${pc.magenta(discord)}
|
|
74
87
|
GitHub: ${pc.blue(repository.url)}
|
|
75
88
|
Docs: ${pc.yellow(homepage)}
|
|
76
|
-
|
|
89
|
+
`,
|
|
77
90
|
)
|
|
78
91
|
.parserConfiguration(YARGS_PARSER_CONFIG)
|
|
79
92
|
.config(args)
|