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

Try and let processes exit on their own instead of calling process.exit(); #241

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
environment:
matrix:
- nodejs_version: '0.10'
- nodejs_version: '5'
- nodejs_version: '4'
- nodejs_version: '0.12'
- nodejs_version: '0.10'
install:
- ps: Install-Product node $env:nodejs_version
- set CI=true
Expand Down
26 changes: 8 additions & 18 deletions lib/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,29 +60,19 @@ process.on('message', function (message) {
});

process.on('ava-exit', function () {
// use a little delay when running on AppVeyor (because it's shit)
var delay = process.env.AVA_APPVEYOR ? 100 : 0;

setTimeout(function () {
process.exit(0);
}, delay);
process.exit(0);
});

process.on('ava-teardown', function () {
var rejections = loudRejection.currentlyUnhandled();

if (rejections.length === 0) {
return exit();
}

rejections = rejections.map(function (rejection) {
return serializeValue(rejection.reason);
});
if (rejections.length !== 0) {
rejections = rejections.map(function (rejection) {
return serializeValue(rejection.reason);
});

send('unhandledRejections', {rejections: rejections});
setTimeout(exit, 100);
});
send('unhandledRejections', {rejections: rejections});
}

function exit() {
send('teardown');
}
});
13 changes: 12 additions & 1 deletion lib/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = function (args) {

var filepath = path.join(__dirname, 'babel.js');
var file = args[0];
var exitTimer;

var options = {
silent: true,
Expand All @@ -30,6 +31,11 @@ module.exports = function (args) {
});

ps.on('exit', function (code) {
if (exitTimer) {
clearTimeout(exitTimer);
exitTimer = null;
}

if (code > 0 && code !== 143) {
return reject(new Error(file + ' exited with a non-zero exit code: ' + code));
}
Expand Down Expand Up @@ -66,7 +72,12 @@ module.exports = function (args) {

// teardown finished, now exit
ps.on('teardown', function () {
send(ps, 'exit');
// use a longer delay when running on AppVeyor (because it's shit)
var delay = process.env.AVA_APPVEYOR ? 200 : 100;

exitTimer = setTimeout(function () {
send(ps, 'exit');
}, delay);
});

// uncaught exception in fork, need to exit
Expand Down
2 changes: 2 additions & 0 deletions test/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function fixture(name) {
}

test('emits test event', function (t) {
t.plan(1);
fork(fixture('generators.js'))
.on('test', function (tt) {
t.equal(tt.title, 'generator function');
Expand All @@ -16,6 +17,7 @@ test('emits test event', function (t) {
});

test('resolves promise with tests info', function (t) {
t.plan(3);
var file = fixture('generators.js');

fork(file)
Expand Down