Skip to content

Commit 0f0c070

Browse files
committed
Merge pull request #680 from sindresorhus/sigabrt
Reject test runs when forks exit with an unexpected signal
2 parents f2c0709 + 8949b85 commit 0f0c070

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

lib/fork.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,15 @@ module.exports = function (file, opts) {
7878
send(ps, 'teardown');
7979
});
8080

81-
ps.on('exit', function (code) {
82-
if (code > 0 && code !== 143) {
81+
ps.on('exit', function (code, signal) {
82+
if (code > 0) {
8383
return reject(new AvaError(relFile + ' exited with a non-zero exit code: ' + code));
8484
}
8585

86+
if (code === null && signal) {
87+
return reject(new AvaError(relFile + ' exited due to ' + signal));
88+
}
89+
8690
if (results) {
8791
resolve(results);
8892
} else {

test/fixture/immediate-3-exit.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
process.exit(3);

test/fork.js

+28
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,34 @@ test('exit after tests are finished', function (t) {
6060
});
6161
});
6262

63+
test('rejects promise if the process exits with a non-zero code', function (t) {
64+
return fork(fixture('immediate-3-exit.js'))
65+
.catch(function (err) {
66+
t.is(err.name, 'AvaError');
67+
t.is(err.message, path.join('test', 'fixture', 'immediate-3-exit.js') + ' exited with a non-zero exit code: 3');
68+
});
69+
});
70+
71+
test('rejects promise if the process exits without results', function (t) {
72+
return fork(fixture('immediate-0-exit.js'))
73+
.catch(function (err) {
74+
t.is(err.name, 'AvaError');
75+
t.is(err.message, 'Test results were not received from ' + path.join('test', 'fixture', 'immediate-0-exit.js'));
76+
});
77+
});
78+
79+
test('rejects promise if the process is killed', function (t) {
80+
var forked = fork(fixture('es2015.js'));
81+
return forked
82+
.on('stats', function () {
83+
this.kill('SIGKILL');
84+
})
85+
.catch(function (err) {
86+
t.is(err.name, 'AvaError');
87+
t.is(err.message, path.join('test', 'fixture', 'es2015.js') + ' exited due to SIGKILL');
88+
});
89+
});
90+
6391
test('fake timers do not break duration', function (t) {
6492
fork(fixture('fake-timers.js'))
6593
.run({})

0 commit comments

Comments
 (0)