Skip to content

Commit 702ec53

Browse files
committed
Address PR review comments mocha org
1 parent 7b36d1e commit 702ec53

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

bin/mocha.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ if (mochaArgs['node-option'] || Object.keys(nodeArgs).length || hasInspect) {
110110
proc.on('exit', (code, signal) => {
111111
process.on('exit', () => {
112112
if (signal) {
113+
const numericSignal =
114+
typeof signal === 'string' ? os.constants.signals[signal] : signal;
113115
if (mochaArgs['posix-exit-codes'] === true) {
114-
process.exitCode = 128 + os.constants.signals[signal];
115-
process.exit(process.exitCode);
116+
process.exit(128 + numericSignal);
116117
} else {
117118
process.kill(process.pid, signal);
118119
}
File renamed without changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
describe('signal suite', function () {
4+
it('test SIGTERM', function () {
5+
process.kill(process.pid, 'SIGTERM');
6+
});
7+
});

test/integration/options/posixExitCodes.spec.js

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,41 @@ var helpers = require('../helpers');
44
var runMocha = helpers.runMocha;
55

66
describe('--posix-exit-codes', function () {
7-
var mocha;
8-
9-
function killSubprocess() {
10-
mocha.kill('SIGKILL');
11-
}
7+
describe('when enabled with node options', function () {
8+
var args = ['--no-warnings', '--posix-exit-codes'];
129

13-
// these two handlers deal with a ctrl-c on command-line
14-
before(function () {
15-
process.on('SIGINT', killSubprocess);
16-
});
10+
it('should exit with code 134 on SIGABRT', function (done) {
11+
var fixture = 'signals-sigabrt.fixture.js';
12+
runMocha(fixture, args, function postmortem(err, res) {
13+
if (err) {
14+
return done(err);
15+
}
16+
expect(res.code, 'to be', 134);
17+
done();
18+
});
19+
});
1720

18-
after(function () {
19-
process.removeListener('SIGINT', killSubprocess);
21+
it('should exit with code 143 on SIGTERM', function (done) {
22+
var fixture = 'signals-sigterm.fixture.js';
23+
runMocha(fixture, args, function postmortem(err, res) {
24+
if (err) {
25+
return done(err);
26+
}
27+
expect(res.code, 'to be', 143);
28+
done();
29+
});
30+
});
2031
});
2132

22-
describe('when enabled with node options', function () {
23-
it('should exit with code 134 on SIGABRT', function (done) {
24-
var fixture = 'posix-exit-codes.fixture.js';
25-
var args = ['--no-warnings', '--posix-exit-codes'];
26-
mocha = runMocha(fixture, args, function postmortem(err, res) {
33+
describe('when not enabled with node options', function () {
34+
it('should exit with code null on SIGABRT', function (done) {
35+
var fixture = 'signals-sigabrt.fixture.js';
36+
var args = ['--no-warnings'];
37+
runMocha(fixture, args, function postmortem(err, res) {
2738
if (err) {
2839
return done(err);
2940
}
30-
expect(res.code, 'to be', 134);
41+
expect(res.code, 'to be', null);
3142
done();
3243
});
3344
});

0 commit comments

Comments
 (0)