Skip to content

Commit

Permalink
reject test runs when forks exit with an unexpected signal
Browse files Browse the repository at this point in the history
  • Loading branch information
novemberborn committed Mar 24, 2016
1 parent 96e1263 commit 8949b85
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ module.exports = function (file, opts) {
send(ps, 'teardown');
});

ps.on('exit', function (code) {
ps.on('exit', function (code, signal) {
if (code > 0) {
return reject(new AvaError(relFile + ' exited with a non-zero exit code: ' + code));
}

if (code === null && signal) {
return reject(new AvaError(relFile + ' exited due to ' + signal));
}

if (results) {
resolve(results);
} else {
Expand Down
12 changes: 12 additions & 0 deletions test/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ test('rejects promise if the process exits without results', function (t) {
});
});

test('rejects promise if the process is killed', function (t) {
var forked = fork(fixture('es2015.js'));
return forked
.on('stats', function () {
this.kill('SIGKILL');
})
.catch(function (err) {
t.is(err.name, 'AvaError');
t.is(err.message, path.join('test', 'fixture', 'es2015.js') + ' exited due to SIGKILL');
});
});

test('fake timers do not break duration', function (t) {
fork(fixture('fake-timers.js'))
.run({})
Expand Down

0 comments on commit 8949b85

Please sign in to comment.