From c84c48a8c3e2ac14f8f0bf4473de8b78688aea6a Mon Sep 17 00:00:00 2001 From: vdemedes Date: Sat, 24 Oct 2015 16:22:08 +0200 Subject: [PATCH] support running the test file only via cli --- index.js | 81 +++++++++++++++++------------------------------------ lib/fork.js | 8 +----- 2 files changed, 27 insertions(+), 62 deletions(-) diff --git a/index.js b/index.js index 23a49ce6c..242c922e5 100644 --- a/index.js +++ b/index.js @@ -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 @@ -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); }); diff --git a/lib/fork.js b/lib/fork.js index a45e52f93..fa7b7738b 100644 --- a/lib/fork.js +++ b/lib/fork.js @@ -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; @@ -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) {