Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject test runs when forks exit with an unexpected signal #680

Merged
merged 3 commits into from
Mar 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions 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) {
if (code > 0 && code !== 143) {
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
1 change: 1 addition & 0 deletions test/fixture/immediate-3-exit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
process.exit(3);
28 changes: 28 additions & 0 deletions test/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,34 @@ test('exit after tests are finished', function (t) {
});
});

test('rejects promise if the process exits with a non-zero code', function (t) {
return fork(fixture('immediate-3-exit.js'))
.catch(function (err) {
t.is(err.name, 'AvaError');
t.is(err.message, path.join('test', 'fixture', 'immediate-3-exit.js') + ' exited with a non-zero exit code: 3');
});
});

test('rejects promise if the process exits without results', function (t) {
return fork(fixture('immediate-0-exit.js'))
.catch(function (err) {
t.is(err.name, 'AvaError');
t.is(err.message, 'Test results were not received from ' + path.join('test', 'fixture', 'immediate-0-exit.js'));
});
});

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