Skip to content

Commit

Permalink
Close #169 PR: Fix Windows onExit failure..
Browse files Browse the repository at this point in the history
  • Loading branch information
jamestalmage authored and sindresorhus committed Nov 10, 2015
1 parent 4399e7b commit 6a8f0e7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ function exit(results) {
// correctly flush the output when multiple test files
process.stdout.write('');

process.exit(failed > 0 ? 1 : 0);
// timeout required to correctly flush stderr on Node 0.10 Windows
setTimeout(function () {
process.exit(failed > 0 ? 1 : 0);
}, 0);
}

function init(files) {
Expand Down
6 changes: 6 additions & 0 deletions lib/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ var transpiled = babel.transformFileSync(testPath, options);
requireFromString(transpiled.code, testPath, {
appendPaths: module.paths
});

process.on('message', function (message) {
if (message['ava-kill-command']) {
process.exit(0);
}
});
2 changes: 1 addition & 1 deletion lib/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function (args) {

// after all tests are finished and results received
// kill the forked process, so AVA can exit safely
ps.kill();
ps.send({'ava-kill-command': true});
});

ps.on('error', reject);
Expand Down
4 changes: 2 additions & 2 deletions test/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ test('exit after tests are finished', function (t) {

fork(fixture('long-running.js'))
.on('exit', function () {
t.ok(Date.now() - start < 10000, 'did NOT wait for setTimeout(fn, 15000');
t.ok(cleanupCompleted, 'did wait for onExit(fn) to complete');
t.ok(Date.now() - start < 10000, 'test waited for a pending setTimeout');
t.ok(cleanupCompleted, 'cleanup did not complete');
})
.on('cleanup-completed', function (event) {
cleanupCompleted = event.completed;
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function execCli(args, cb) {
args = [args];
}

childProcess.execFile('../cli.js', args, {cwd: __dirname}, cb);
childProcess.execFile(process.execPath, ['../cli.js'].concat(args), {cwd: __dirname}, cb);
}

test('run test', function (t) {
Expand Down

0 comments on commit 6a8f0e7

Please sign in to comment.