Skip to content

Support running the test file only via CLI #98

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

Merged
merged 1 commit into from
Oct 24, 2015
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
81 changes: 26 additions & 55 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
var setImmediate = require('set-immediate-shim');
var Runner = require('./lib/runner');
var runner = new Runner();
var log = require('./lib/logger');

var isFailFast = process.argv.indexOf('--fail-fast') !== -1;
var isForked = process.env.AVA_FORK;

// if fail-fast is enabled, use this variable to detect,
// that no more tests should be logged
Expand All @@ -27,70 +25,43 @@ function test(err, title, duration) {
return;
}

if (isForked) {
if (err) {
err = serializeError(err);
}

process.send({
name: 'test',
data: {
err: err || {},
title: title,
duration: duration
}
});
if (err) {
err = serializeError(err);
}

if (err && isFailFast) {
isFailed = true;
exit();
process.send({
name: 'test',
data: {
err: err || {},
title: title,
duration: duration
}
});

return;
if (err && isFailFast) {
isFailed = true;
exit();
}

log.test(err, title, duration);
}

function exit() {
if (isForked) {
// serialize errors
runner.results.forEach(function (result) {
if (result.error) {
result.error = serializeError(result.error);
}
});

process.send({
name: 'results',
data: {
stats: runner.stats,
tests: runner.results
}
});

return;
}

var stats = runner.stats;
var results = runner.results;

log.write();
log.report(stats.passCount, stats.failCount);
log.write();

if (stats.failCount > 0) {
log.errors(results);
}
// serialize errors
runner.results.forEach(function (result) {
if (result.error) {
result.error = serializeError(result.error);
}
});

process.exit(stats.failCount > 0 ? 1 : 0);
process.send({
name: 'results',
data: {
stats: runner.stats,
tests: runner.results
}
});
}

setImmediate(function () {
if (!isForked) {
log.write();
}

runner.on('test', test);
runner.run().then(exit);
});
Expand Down
8 changes: 1 addition & 7 deletions lib/fork.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

var childProcess = require('child_process');
var Promise = require('bluebird');
var assign = require('object-assign');
var join = require('path').join;

module.exports = fork;
Expand All @@ -15,12 +14,7 @@ function fork(args) {
var babel = join(__dirname, 'babel.js');
var file = args[0];

var options = {
silent: true,
env: assign({}, process.env, {AVA_FORK: 1})
};

var ps = childProcess.fork(babel, args, options);
var ps = childProcess.fork(babel, args, {silent: true});

var promise = new Promise(function (resolve, reject) {
ps.on('results', function (results) {
Expand Down