Skip to content

Commit

Permalink
Address PR review comments mocha org
Browse files Browse the repository at this point in the history
  • Loading branch information
73rhodes committed Mar 18, 2024
1 parent 3b99517 commit 2150c30
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 19 deletions.
5 changes: 3 additions & 2 deletions bin/mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 7 additions & 0 deletions test/integration/fixtures/signals-sigterm.fixture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

describe('signal suite', function () {
it('test SIGTERM', function () {
process.kill(process.pid, 'SIGTERM');
});
});
45 changes: 28 additions & 17 deletions test/integration/options/posixExitCodes.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down

0 comments on commit 2150c30

Please sign in to comment.