mocha 11.2.2 → 11.4.0
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/bin/mocha.js +8 -2
- package/lib/cli/run-helpers.js +3 -1
- package/lib/cli/run-option-metadata.js +1 -0
- package/lib/cli/run.js +4 -0
- package/mocha.js +1754 -992
- package/mocha.js.map +1 -1
- package/package.json +7 -4
package/bin/mocha.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* @private
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
const os = require('node:os');
|
|
13
14
|
const {loadOptions} = require('../lib/cli/options');
|
|
14
15
|
const {
|
|
15
16
|
unparseNodeFlags,
|
|
@@ -22,6 +23,7 @@ const {aliases} = require('../lib/cli/run-option-metadata');
|
|
|
22
23
|
|
|
23
24
|
const mochaArgs = {};
|
|
24
25
|
const nodeArgs = {};
|
|
26
|
+
const SIGNAL_OFFSET = 128;
|
|
25
27
|
let hasInspect = false;
|
|
26
28
|
|
|
27
29
|
const opts = loadOptions(process.argv.slice(2));
|
|
@@ -109,9 +111,13 @@ if (mochaArgs['node-option'] || Object.keys(nodeArgs).length || hasInspect) {
|
|
|
109
111
|
proc.on('exit', (code, signal) => {
|
|
110
112
|
process.on('exit', () => {
|
|
111
113
|
if (signal) {
|
|
114
|
+
signal = typeof signal === 'string' ? os.constants.signals[signal] : signal;
|
|
115
|
+
if (mochaArgs['posix-exit-codes'] === true) {
|
|
116
|
+
process.exitCode = SIGNAL_OFFSET + signal;
|
|
117
|
+
}
|
|
112
118
|
process.kill(process.pid, signal);
|
|
113
119
|
} else {
|
|
114
|
-
process.exit(code);
|
|
120
|
+
process.exit(Math.min(code, mochaArgs['posix-exit-codes'] ? 1 : 255));
|
|
115
121
|
}
|
|
116
122
|
});
|
|
117
123
|
});
|
|
@@ -126,7 +132,7 @@ if (mochaArgs['node-option'] || Object.keys(nodeArgs).length || hasInspect) {
|
|
|
126
132
|
// be needed.
|
|
127
133
|
if (!args.parallel || args.jobs < 2) {
|
|
128
134
|
// win32 does not support SIGTERM, so use next best thing.
|
|
129
|
-
if (
|
|
135
|
+
if (os.platform() === 'win32') {
|
|
130
136
|
proc.kill('SIGKILL');
|
|
131
137
|
} else {
|
|
132
138
|
// using SIGKILL won't cleanly close the output streams, which can result
|
package/lib/cli/run-helpers.js
CHANGED
|
@@ -27,7 +27,7 @@ const {UnmatchedFile} = require('./collect-files');
|
|
|
27
27
|
*/
|
|
28
28
|
const exitMochaLater = clampedCode => {
|
|
29
29
|
process.on('exit', () => {
|
|
30
|
-
process.exitCode = clampedCode;
|
|
30
|
+
process.exitCode = Math.min(clampedCode, process.argv.includes('--posix-exit-codes') ? 1 : 255);
|
|
31
31
|
});
|
|
32
32
|
};
|
|
33
33
|
|
|
@@ -39,6 +39,8 @@ const exitMochaLater = clampedCode => {
|
|
|
39
39
|
* @private
|
|
40
40
|
*/
|
|
41
41
|
const exitMocha = clampedCode => {
|
|
42
|
+
const usePosixExitCodes = process.argv.includes('--posix-exit-codes');
|
|
43
|
+
clampedCode = Math.min(clampedCode, usePosixExitCodes ? 1 : 255);
|
|
42
44
|
let draining = 0;
|
|
43
45
|
|
|
44
46
|
// Eagerly set the process's exit code in case stream.write doesn't
|
package/lib/cli/run.js
CHANGED
|
@@ -195,6 +195,10 @@ exports.builder = yargs =>
|
|
|
195
195
|
description: 'Run tests in parallel',
|
|
196
196
|
group: GROUPS.RULES
|
|
197
197
|
},
|
|
198
|
+
'posix-exit-codes': {
|
|
199
|
+
description: 'Use POSIX and UNIX shell exit codes as Mocha\'s return value',
|
|
200
|
+
group: GROUPS.RULES
|
|
201
|
+
},
|
|
198
202
|
recursive: {
|
|
199
203
|
description: 'Look for tests in subdirectories',
|
|
200
204
|
group: GROUPS.FILES
|