From 8999b7b787a95b3d447df0daf025fd0d7c5d02ea Mon Sep 17 00:00:00 2001 From: Darren DeRidder Date: Tue, 23 May 2023 17:53:18 -0400 Subject: [PATCH 01/13] Option to use posix exit code upon fatal signal --- bin/mocha.js | 10 ++++-- lib/cli/run-option-metadata.js | 1 + lib/cli/run.js | 4 +++ .../fixtures/posix-exit-codes.fixture.js | 7 ++++ .../options/posixExitCodes.spec.js | 36 +++++++++++++++++++ 5 files changed, 56 insertions(+), 2 deletions(-) mode change 100644 => 100755 bin/mocha.js create mode 100644 test/integration/fixtures/posix-exit-codes.fixture.js create mode 100644 test/integration/options/posixExitCodes.spec.js diff --git a/bin/mocha.js b/bin/mocha.js old mode 100644 new mode 100755 index fb58e65fcd..735bc42e95 --- a/bin/mocha.js +++ b/bin/mocha.js @@ -10,6 +10,7 @@ * @private */ +const os = require('os'); const {loadOptions} = require('../lib/cli/options'); const { unparseNodeFlags, @@ -109,7 +110,12 @@ if (mochaArgs['node-option'] || Object.keys(nodeArgs).length || hasInspect) { proc.on('exit', (code, signal) => { process.on('exit', () => { if (signal) { - process.kill(process.pid, signal); + if (mochaArgs['posix-exit-codes'] === true) { + process.exitCode = 128 + os.constants.signals[signal]; + process.exit(process.exitCode); + } else { + process.kill(process.pid, signal); + } } else { process.exit(code); } @@ -126,7 +132,7 @@ if (mochaArgs['node-option'] || Object.keys(nodeArgs).length || hasInspect) { // be needed. if (!args.parallel || args.jobs < 2) { // win32 does not support SIGTERM, so use next best thing. - if (require('os').platform() === 'win32') { + if (os.platform() === 'win32') { proc.kill('SIGKILL'); } else { // using SIGKILL won't cleanly close the output streams, which can result diff --git a/lib/cli/run-option-metadata.js b/lib/cli/run-option-metadata.js index 492608fbdd..91a0282e7b 100644 --- a/lib/cli/run-option-metadata.js +++ b/lib/cli/run-option-metadata.js @@ -45,6 +45,7 @@ const TYPES = (exports.types = { 'list-reporters', 'no-colors', 'parallel', + 'posix-exit-codes', 'recursive', 'sort', 'watch' diff --git a/lib/cli/run.js b/lib/cli/run.js index fbbe510e94..a4830e97e6 100644 --- a/lib/cli/run.js +++ b/lib/cli/run.js @@ -190,6 +190,10 @@ exports.builder = yargs => description: 'Run tests in parallel', group: GROUPS.RULES }, + 'posix-exit-codes': { + description: 'Use posix exit codes for fatal signals', + group: GROUPS.RULES + }, recursive: { description: 'Look for tests in subdirectories', group: GROUPS.FILES diff --git a/test/integration/fixtures/posix-exit-codes.fixture.js b/test/integration/fixtures/posix-exit-codes.fixture.js new file mode 100644 index 0000000000..037111097b --- /dev/null +++ b/test/integration/fixtures/posix-exit-codes.fixture.js @@ -0,0 +1,7 @@ +'use strict'; + +describe('signal suite', function () { + it('test SIGABRT', function () { + process.kill(process.pid, 'SIGABRT'); + }); +}); diff --git a/test/integration/options/posixExitCodes.spec.js b/test/integration/options/posixExitCodes.spec.js new file mode 100644 index 0000000000..63fa8c9726 --- /dev/null +++ b/test/integration/options/posixExitCodes.spec.js @@ -0,0 +1,36 @@ +'use strict'; + +var helpers = require('../helpers'); +var runMocha = helpers.runMocha; + +describe('--posix-exit-codes', function () { + // subprocess + var mocha; + + function killSubprocess() { + mocha.kill('SIGKILL'); + } + + // these two handlers deal with a ctrl-c on command-line + before(function () { + process.on('SIGINT', killSubprocess); + }); + + after(function () { + process.removeListener('SIGINT', killSubprocess); + }); + + describe('when enabled with node options', function () { + it('should exit with code 134 on SIGABRT', function (done) { + var fixture = 'posix-exit-codes.fixture.js'; + var args = ['--no-warnings', '--posix-exit-codes']; + mocha = runMocha(fixture, args, function postmortem(err, res) { + if (err) { + return done(err); + } + expect(res.code, 'to be', 134); + done(); + }); + }); + }); +}); From 3b995174555f28327cfe85300ad6cf7fb6f1e5e3 Mon Sep 17 00:00:00 2001 From: Darren DeRidder <73rhodes@users.noreply.github.com> Date: Fri, 15 Mar 2024 23:18:14 +0900 Subject: [PATCH 02/13] Update test/integration/options/posixExitCodes.spec.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Josh Goldberg ✨ --- test/integration/options/posixExitCodes.spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/integration/options/posixExitCodes.spec.js b/test/integration/options/posixExitCodes.spec.js index 63fa8c9726..3a9e59c0b1 100644 --- a/test/integration/options/posixExitCodes.spec.js +++ b/test/integration/options/posixExitCodes.spec.js @@ -4,7 +4,6 @@ var helpers = require('../helpers'); var runMocha = helpers.runMocha; describe('--posix-exit-codes', function () { - // subprocess var mocha; function killSubprocess() { From 2150c30161b9ca55d95432976c3259724d7c214b Mon Sep 17 00:00:00 2001 From: Darren DeRidder Date: Mon, 18 Mar 2024 13:34:59 -0400 Subject: [PATCH 03/13] Address PR review comments mocha org --- bin/mocha.js | 5 ++- ....fixture.js => signals-sigabrt.fixture.js} | 0 .../fixtures/signals-sigterm.fixture.js | 7 +++ .../options/posixExitCodes.spec.js | 45 ++++++++++++------- 4 files changed, 38 insertions(+), 19 deletions(-) rename test/integration/fixtures/{posix-exit-codes.fixture.js => signals-sigabrt.fixture.js} (100%) create mode 100644 test/integration/fixtures/signals-sigterm.fixture.js diff --git a/bin/mocha.js b/bin/mocha.js index 735bc42e95..dee9d3a67d 100755 --- a/bin/mocha.js +++ b/bin/mocha.js @@ -110,9 +110,10 @@ if (mochaArgs['node-option'] || Object.keys(nodeArgs).length || hasInspect) { proc.on('exit', (code, signal) => { process.on('exit', () => { if (signal) { + const numericSignal = + typeof signal === 'string' ? os.constants.signals[signal] : signal; if (mochaArgs['posix-exit-codes'] === true) { - process.exitCode = 128 + os.constants.signals[signal]; - process.exit(process.exitCode); + process.exit(128 + numericSignal); } else { process.kill(process.pid, signal); } diff --git a/test/integration/fixtures/posix-exit-codes.fixture.js b/test/integration/fixtures/signals-sigabrt.fixture.js similarity index 100% rename from test/integration/fixtures/posix-exit-codes.fixture.js rename to test/integration/fixtures/signals-sigabrt.fixture.js diff --git a/test/integration/fixtures/signals-sigterm.fixture.js b/test/integration/fixtures/signals-sigterm.fixture.js new file mode 100644 index 0000000000..2f1d01c700 --- /dev/null +++ b/test/integration/fixtures/signals-sigterm.fixture.js @@ -0,0 +1,7 @@ +'use strict'; + +describe('signal suite', function () { + it('test SIGTERM', function () { + process.kill(process.pid, 'SIGTERM'); + }); +}); diff --git a/test/integration/options/posixExitCodes.spec.js b/test/integration/options/posixExitCodes.spec.js index 3a9e59c0b1..f33f65a0ff 100644 --- a/test/integration/options/posixExitCodes.spec.js +++ b/test/integration/options/posixExitCodes.spec.js @@ -4,30 +4,41 @@ var helpers = require('../helpers'); var runMocha = helpers.runMocha; describe('--posix-exit-codes', function () { - var mocha; - - function killSubprocess() { - mocha.kill('SIGKILL'); - } + describe('when enabled with node options', function () { + var args = ['--no-warnings', '--posix-exit-codes']; - // these two handlers deal with a ctrl-c on command-line - before(function () { - process.on('SIGINT', killSubprocess); - }); + it('should exit with code 134 on SIGABRT', function (done) { + var fixture = 'signals-sigabrt.fixture.js'; + runMocha(fixture, args, function postmortem(err, res) { + if (err) { + return done(err); + } + expect(res.code, 'to be', 134); + done(); + }); + }); - after(function () { - process.removeListener('SIGINT', killSubprocess); + it('should exit with code 143 on SIGTERM', function (done) { + var fixture = 'signals-sigterm.fixture.js'; + runMocha(fixture, args, function postmortem(err, res) { + if (err) { + return done(err); + } + expect(res.code, 'to be', 143); + done(); + }); + }); }); - describe('when enabled with node options', function () { - it('should exit with code 134 on SIGABRT', function (done) { - var fixture = 'posix-exit-codes.fixture.js'; - var args = ['--no-warnings', '--posix-exit-codes']; - mocha = runMocha(fixture, args, function postmortem(err, res) { + describe('when not enabled with node options', function () { + it('should exit with code null on SIGABRT', function (done) { + var fixture = 'signals-sigabrt.fixture.js'; + var args = ['--no-warnings']; + runMocha(fixture, args, function postmortem(err, res) { if (err) { return done(err); } - expect(res.code, 'to be', 134); + expect(res.code, 'to be', null); done(); }); }); From 62528c5d93f595f36f746cab1b61b67de79e9a5c Mon Sep 17 00:00:00 2001 From: Darren DeRidder Date: Mon, 18 Mar 2024 13:34:59 -0400 Subject: [PATCH 04/13] Address PR review comments mocha org --- docs/index.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/index.md b/docs/index.md index b6a70eba7c..ebc7758922 100644 --- a/docs/index.md +++ b/docs/index.md @@ -936,6 +936,10 @@ Define a global variable name. For example, suppose your app deliberately expose By using this option in conjunction with `--check-leaks`, you can specify a whitelist of known global variables that you _expect_ to leak into global scope. +### `--posix-exit-codes` + +Exits with standard POSIX exit codes instead of the number of faled tests. + ### `--retries ` Retries failed tests `n` times. From ad30057dd1aa85a2f066ee2835a8574f4e61f2a8 Mon Sep 17 00:00:00 2001 From: Darren DeRidder <73rhodes@users.noreply.github.com> Date: Mon, 25 Mar 2024 22:58:28 +0900 Subject: [PATCH 05/13] Update docs/index.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Josh Goldberg ✨ --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 7fc0293e03..27795431b8 100644 --- a/docs/index.md +++ b/docs/index.md @@ -938,7 +938,7 @@ By using this option in conjunction with `--check-leaks`, you can specify a whit ### `--posix-exit-codes` -Exits with standard POSIX exit codes instead of the number of faled tests. +Exits with standard POSIX exit codes instead of the number of failed tests. ### `--retries ` From 592f071845f54407172e1a1a59df84278f2d8a18 Mon Sep 17 00:00:00 2001 From: Darren DeRidder Date: Thu, 11 Apr 2024 15:19:57 -0400 Subject: [PATCH 06/13] Fix exit code when no signal caught --- bin/mocha.js | 2 +- test/integration/options/posixExitCodes.spec.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bin/mocha.js b/bin/mocha.js index dee9d3a67d..d5f914a462 100755 --- a/bin/mocha.js +++ b/bin/mocha.js @@ -118,7 +118,7 @@ if (mochaArgs['node-option'] || Object.keys(nodeArgs).length || hasInspect) { process.kill(process.pid, signal); } } else { - process.exit(code); + process.exit((mochaArgs['posix-exit-codes'] === true) ? 0 : code); } }); }); diff --git a/test/integration/options/posixExitCodes.spec.js b/test/integration/options/posixExitCodes.spec.js index f33f65a0ff..ea16462e87 100644 --- a/test/integration/options/posixExitCodes.spec.js +++ b/test/integration/options/posixExitCodes.spec.js @@ -42,5 +42,17 @@ describe('--posix-exit-codes', function () { done(); }); }); + + it('should exit with the number of failed tests', function (done) { + var fixture = 'failing.fixture.js'; // one failing test + var args = ['--no-warnings']; + runMocha(fixture, args, function postmortem(err, res) { + if (err) { + return done(err); + } + expect(res.code, 'to be', 1); + done(); + }); + }); }); }); From 34f282212aee6d808c480169e6368294a2bc03de Mon Sep 17 00:00:00 2001 From: Darren DeRidder Date: Thu, 11 Apr 2024 15:45:57 -0400 Subject: [PATCH 07/13] Coverage for posix exit code with normally failing tests --- test/integration/options/posixExitCodes.spec.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/test/integration/options/posixExitCodes.spec.js b/test/integration/options/posixExitCodes.spec.js index ea16462e87..4510a7c42c 100644 --- a/test/integration/options/posixExitCodes.spec.js +++ b/test/integration/options/posixExitCodes.spec.js @@ -4,7 +4,7 @@ var helpers = require('../helpers'); var runMocha = helpers.runMocha; describe('--posix-exit-codes', function () { - describe('when enabled with node options', function () { + describe('when enabled, and with node options', function () { var args = ['--no-warnings', '--posix-exit-codes']; it('should exit with code 134 on SIGABRT', function (done) { @@ -28,9 +28,20 @@ describe('--posix-exit-codes', function () { done(); }); }); + + it('should exit with code 0 even if there are test failures', function (done) { + var fixture = 'failing.fixture.js'; + runMocha(fixture, args, function postmortem(err, res) { + if (err) { + return done(err); + } + expect(res.code, 'to be', 0); + done(); + }); + }); }); - describe('when not enabled with node options', function () { + describe('when not enabled, and with node options', function () { it('should exit with code null on SIGABRT', function (done) { var fixture = 'signals-sigabrt.fixture.js'; var args = ['--no-warnings']; From b6e6d300803b2fa47a0030f72285f8b768e6eb6c Mon Sep 17 00:00:00 2001 From: Darren DeRidder <73rhodes@users.noreply.github.com> Date: Mon, 15 Apr 2024 23:58:38 +0900 Subject: [PATCH 08/13] Update docs/index.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Josh Goldberg ✨ --- docs/index.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/index.md b/docs/index.md index 27795431b8..807ae159c5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -940,6 +940,14 @@ By using this option in conjunction with `--check-leaks`, you can specify a whit Exits with standard POSIX exit codes instead of the number of failed tests. +Those exit codes are: + +* `0`: if all tests passed +* `1`: if any test failed +* `128 + ` if given a signal, such as: + * 134: `SIGABRT` (`128 + 6`) + * 143: `SIGTERM` (`128 + 15`) + ### `--retries ` Retries failed tests `n` times. From d2991a18c1b02c7f23e8abc62631b06d6dfa3b3a Mon Sep 17 00:00:00 2001 From: Darren DeRidder Date: Mon, 15 Apr 2024 13:44:54 -0400 Subject: [PATCH 09/13] Address PR comments; use os.constants --- bin/mocha.js | 9 ++++++-- lib/cli/run.js | 2 +- test/integration/fixtures/failing.fixture.js | 23 +++++++++++++++++++ .../options/posixExitCodes.spec.js | 22 +++++++++++------- 4 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 test/integration/fixtures/failing.fixture.js diff --git a/bin/mocha.js b/bin/mocha.js index d5f914a462..27e02fd5e9 100755 --- a/bin/mocha.js +++ b/bin/mocha.js @@ -23,6 +23,9 @@ const {aliases} = require('../lib/cli/run-option-metadata'); const mochaArgs = {}; const nodeArgs = {}; +const EXIT_SUCCESS = 0; +const EXIT_FAILURE = 1; +const SIGNAL_OFFSET= 128; let hasInspect = false; const opts = loadOptions(process.argv.slice(2)); @@ -113,12 +116,14 @@ if (mochaArgs['node-option'] || Object.keys(nodeArgs).length || hasInspect) { const numericSignal = typeof signal === 'string' ? os.constants.signals[signal] : signal; if (mochaArgs['posix-exit-codes'] === true) { - process.exit(128 + numericSignal); + process.exit(SIGNAL_OFFSET + numericSignal); } else { process.kill(process.pid, signal); } + } else if (code !== 0 && mochaArgs['posix-exit-codes'] === true) { + process.exit(EXIT_FAILURE); } else { - process.exit((mochaArgs['posix-exit-codes'] === true) ? 0 : code); + process.exit(code); } }); }); diff --git a/lib/cli/run.js b/lib/cli/run.js index a4830e97e6..a50418d3f7 100644 --- a/lib/cli/run.js +++ b/lib/cli/run.js @@ -191,7 +191,7 @@ exports.builder = yargs => group: GROUPS.RULES }, 'posix-exit-codes': { - description: 'Use posix exit codes for fatal signals', + description: 'Use POSIX and UNIX shell exit codes as Mocha\'s return value', group: GROUPS.RULES }, recursive: { diff --git a/test/integration/fixtures/failing.fixture.js b/test/integration/fixtures/failing.fixture.js new file mode 100644 index 0000000000..337d628991 --- /dev/null +++ b/test/integration/fixtures/failing.fixture.js @@ -0,0 +1,23 @@ +'use strict'; + +// One passing test and three failing tests + +var assert = require('assert'); + +describe('suite', function () { + it('test1', function () { + assert(true); + }); + + it('test2', function () { + assert(false); + }); + + it('test3', function () { + assert(false); + }); + + it('test4', function () { + assert(false); + }); +}); diff --git a/test/integration/options/posixExitCodes.spec.js b/test/integration/options/posixExitCodes.spec.js index 4510a7c42c..c86a7105b3 100644 --- a/test/integration/options/posixExitCodes.spec.js +++ b/test/integration/options/posixExitCodes.spec.js @@ -2,40 +2,45 @@ var helpers = require('../helpers'); var runMocha = helpers.runMocha; +var os = require('os'); + +const EXIT_SUCCESS = 0; +const EXIT_FAILURE = 1; +const SIGNAL_OFFSET = 128; describe('--posix-exit-codes', function () { describe('when enabled, and with node options', function () { var args = ['--no-warnings', '--posix-exit-codes']; - it('should exit with code 134 on SIGABRT', function (done) { + it('should exit with correct POSIX shell code on SIGABRT', function (done) { var fixture = 'signals-sigabrt.fixture.js'; runMocha(fixture, args, function postmortem(err, res) { if (err) { return done(err); } - expect(res.code, 'to be', 134); + expect(res.code, 'to be', SIGNAL_OFFSET + os.constants.signals.SIGABRT); done(); }); }); - it('should exit with code 143 on SIGTERM', function (done) { + it('should exit with correct POSIX shell code on SIGTERM', function (done) { var fixture = 'signals-sigterm.fixture.js'; runMocha(fixture, args, function postmortem(err, res) { if (err) { return done(err); } - expect(res.code, 'to be', 143); + expect(res.code, 'to be', SIGNAL_OFFSET + os.constants.signals.SIGTERM); done(); }); }); - it('should exit with code 0 even if there are test failures', function (done) { + it('should exit with code 1 if there are test failures', function (done) { var fixture = 'failing.fixture.js'; runMocha(fixture, args, function postmortem(err, res) { if (err) { return done(err); } - expect(res.code, 'to be', 0); + expect(res.code, 'to be', EXIT_FAILURE); done(); }); }); @@ -55,13 +60,14 @@ describe('--posix-exit-codes', function () { }); it('should exit with the number of failed tests', function (done) { - var fixture = 'failing.fixture.js'; // one failing test + var fixture = 'failing.fixture.js'; // contains three failing tests + var numFailures = 3; var args = ['--no-warnings']; runMocha(fixture, args, function postmortem(err, res) { if (err) { return done(err); } - expect(res.code, 'to be', 1); + expect(res.code, 'to be', numFailures); done(); }); }); From 609f94fe3c4c885b144dbe8474e20fccded583ad Mon Sep 17 00:00:00 2001 From: Darren DeRidder Date: Tue, 23 Apr 2024 11:02:13 -0400 Subject: [PATCH 10/13] Remove test that asserts the problematic behavior --- test/integration/options/posixExitCodes.spec.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/test/integration/options/posixExitCodes.spec.js b/test/integration/options/posixExitCodes.spec.js index c86a7105b3..22c4f41aa3 100644 --- a/test/integration/options/posixExitCodes.spec.js +++ b/test/integration/options/posixExitCodes.spec.js @@ -47,18 +47,6 @@ describe('--posix-exit-codes', function () { }); describe('when not enabled, and with node options', function () { - it('should exit with code null on SIGABRT', function (done) { - var fixture = 'signals-sigabrt.fixture.js'; - var args = ['--no-warnings']; - runMocha(fixture, args, function postmortem(err, res) { - if (err) { - return done(err); - } - expect(res.code, 'to be', null); - done(); - }); - }); - it('should exit with the number of failed tests', function (done) { var fixture = 'failing.fixture.js'; // contains three failing tests var numFailures = 3; From 0aa939fc186c4b81defa05493fabcb7377c1d8c2 Mon Sep 17 00:00:00 2001 From: Darren DeRidder Date: Fri, 26 Apr 2024 15:46:34 -0400 Subject: [PATCH 11/13] Omit win32 from signals test suite --- .../options/posixExitCodes.spec.js | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/test/integration/options/posixExitCodes.spec.js b/test/integration/options/posixExitCodes.spec.js index 22c4f41aa3..5fd82f1951 100644 --- a/test/integration/options/posixExitCodes.spec.js +++ b/test/integration/options/posixExitCodes.spec.js @@ -9,42 +9,44 @@ const EXIT_FAILURE = 1; const SIGNAL_OFFSET = 128; describe('--posix-exit-codes', function () { - describe('when enabled, and with node options', function () { - var args = ['--no-warnings', '--posix-exit-codes']; + if (os.platform() !== 'win32') { // SIGTERM is not supported on Windows + describe('when enabled, and with node options', function () { + var args = ['--no-warnings', '--posix-exit-codes']; - it('should exit with correct POSIX shell code on SIGABRT', function (done) { - var fixture = 'signals-sigabrt.fixture.js'; - runMocha(fixture, args, function postmortem(err, res) { - if (err) { - return done(err); - } - expect(res.code, 'to be', SIGNAL_OFFSET + os.constants.signals.SIGABRT); - done(); + it('should exit with correct POSIX shell code on SIGABRT', function (done) { + var fixture = 'signals-sigabrt.fixture.js'; + runMocha(fixture, args, function postmortem(err, res) { + if (err) { + return done(err); + } + expect(res.code, 'to be', SIGNAL_OFFSET + os.constants.signals.SIGABRT); + done(); + }); }); - }); - it('should exit with correct POSIX shell code on SIGTERM', function (done) { - var fixture = 'signals-sigterm.fixture.js'; - runMocha(fixture, args, function postmortem(err, res) { - if (err) { - return done(err); - } - expect(res.code, 'to be', SIGNAL_OFFSET + os.constants.signals.SIGTERM); - done(); + it('should exit with correct POSIX shell code on SIGTERM', function (done) { + var fixture = 'signals-sigterm.fixture.js'; + runMocha(fixture, args, function postmortem(err, res) { + if (err) { + return done(err); + } + expect(res.code, 'to be', SIGNAL_OFFSET + os.constants.signals.SIGTERM); + done(); + }); }); - }); - it('should exit with code 1 if there are test failures', function (done) { - var fixture = 'failing.fixture.js'; - runMocha(fixture, args, function postmortem(err, res) { - if (err) { - return done(err); - } - expect(res.code, 'to be', EXIT_FAILURE); - done(); + it('should exit with code 1 if there are test failures', function (done) { + var fixture = 'failing.fixture.js'; + runMocha(fixture, args, function postmortem(err, res) { + if (err) { + return done(err); + } + expect(res.code, 'to be', EXIT_FAILURE); + done(); + }); }); }); - }); + } describe('when not enabled, and with node options', function () { it('should exit with the number of failed tests', function (done) { From 6d237fcf373bc7d2cb4445f8dbf98e7176464715 Mon Sep 17 00:00:00 2001 From: Darren DeRidder <73rhodes@users.noreply.github.com> Date: Thu, 2 May 2024 03:12:41 +0900 Subject: [PATCH 12/13] Update docs/index.md --- docs/index.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/index.md b/docs/index.md index f7d512c9b8..a2d701b164 100644 --- a/docs/index.md +++ b/docs/index.md @@ -942,11 +942,11 @@ Exits with standard POSIX exit codes instead of the number of failed tests. Those exit codes are: -* `0`: if all tests passed -* `1`: if any test failed -* `128 + ` if given a signal, such as: - * 134: `SIGABRT` (`128 + 6`) - * 143: `SIGTERM` (`128 + 15`) +- `0`: if all tests passed +- `1`: if any test failed +- `128 + ` if given a signal, such as: + - 134: `SIGABRT` (`128 + 6`) + - 143: `SIGTERM` (`128 + 15`) ### `--retries ` From ca78dbc39ce62f712deff0cb9e94cf7b2a01c22e Mon Sep 17 00:00:00 2001 From: Darren DeRidder <73rhodes@users.noreply.github.com> Date: Sat, 8 Jun 2024 02:53:30 +0900 Subject: [PATCH 13/13] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ed5d6ea47e..064f392a2c 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ "log-symbols": "4.1.0", "minimatch": "5.0.1", "ms": "2.1.3", - "serialize-javascript": "6.0.0", + "serialize-javascript": "^6.0.2", "strip-json-comments": "3.1.1", "supports-color": "8.1.1", "workerpool": "6.2.1",