diff --git a/cli.js b/cli.js index 8b01b10d3..2029410ce 100755 --- a/cli.js +++ b/cli.js @@ -81,16 +81,14 @@ function stats(stats) { } function test(data) { - var isError = data.err.message; - - var prefix = ''; + var isError = data.error.message; if (fileCount > 1) { - prefix = prefixTitle(data.file); + data.title = prefixTitle(data.file) + data.title; } if (isError) { - log.error(prefix + data.title, chalk.red(data.err.message)); + log.error(data.title, chalk.red(data.error.message)); errors.push(data); } else { @@ -100,7 +98,7 @@ function test(data) { return; } - log.test(null, prefix + data.title, data.duration); + log.test(data); } } diff --git a/index.js b/index.js index 5426119ff..366f4aa28 100644 --- a/index.js +++ b/index.js @@ -26,26 +26,24 @@ var isFailed = false; Error.stackTraceLimit = Infinity; -function test(err, title, duration, type) { +function test(props) { if (isFailed) { return; } // don't display anything, if it's a passed hook - if (!err && type !== 'test') { + if (!props.error && props.type !== 'test') { return; } + props.error = props.error ? serializeError(props.error) : {}; + process.send({ name: 'test', - data: { - err: err ? serializeError(err) : {}, - title: title, - duration: duration - } + data: props }); - if (err && hasFlag('fail-fast')) { + if (props.error && hasFlag('fail-fast')) { isFailed = true; exit(); } diff --git a/lib/logger.js b/lib/logger.js index 679d28c82..c7382b309 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -33,9 +33,9 @@ x.writelpad = log.writelpad.bind(log); x.success = log.success.bind(log); x.error = log.error.bind(log); -x.test = function (err, title, duration) { - if (err) { - log.error(title, chalk.red(err.message)); +x.test = function (props) { + if (props.err) { + log.error(props.title, chalk.red(props.err.message)); return; } @@ -45,8 +45,8 @@ x.test = function (err, title, duration) { // display duration only over a threshold var threshold = 100; - var dur = duration > threshold ? chalk.gray.dim(' (' + prettyMs(duration) + ')') : ''; - log.success(title + dur); + var dur = props.duration > threshold ? chalk.gray.dim(' (' + prettyMs(props.duration) + ')') : ''; + log.success(props.title + dur); }; x.errors = function (results) { diff --git a/lib/runner.js b/lib/runner.js index 53441a29b..1615d9ddd 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -158,14 +158,15 @@ Runner.prototype._addTestResult = function (test) { this.stats.failCount++; } - this.results.push({ + var props = { duration: test.duration, title: test.title, error: test.assertError, type: test.type - }); + }; - this.emit('test', test.assertError, test.title, test.duration, test.type); + this.results.push(props); + this.emit('test', props); }; Runner.prototype.run = function () { diff --git a/test/test.js b/test/test.js index 8e14d8c32..0e7809dac 100644 --- a/test/test.js +++ b/test/test.js @@ -405,10 +405,10 @@ test('runner have test event', function (t) { a.end(); }); - runner.on('test', function (err, title, duration) { - t.error(err); - t.equal(title, 'foo'); - t.ok(duration !== undefined); + runner.on('test', function (props) { + t.error(props.error); + t.equal(props.title, 'foo'); + t.notEqual(props.duration, undefined); t.end(); }); @@ -847,11 +847,11 @@ test('test types and titles', function (t) { {type: 'hook', title: 'pass'} ]; - runner.on('test', function (err, title, duration, type) { + runner.on('test', function (props) { var test = tests.shift(); - t.is(test.title, title); - t.is(test.type, type); + t.is(test.title, props.title); + t.is(test.type, props.type); }); runner.run().then(t.end); @@ -956,7 +956,7 @@ test('don\'t display hook title if it did not fail', function (t) { fork(path.join(__dirname, 'fixture', 'hooks-passing.js')) .on('test', function (test) { - t.deepEqual(test.err, {}); + t.deepEqual(test.error, {}); t.is(test.title, 'pass'); }) .then(function () { @@ -969,7 +969,7 @@ test('display hook title if it failed', function (t) { fork(path.join(__dirname, 'fixture', 'hooks-failing.js')) .on('test', function (test) { - t.is(test.err.name, 'AssertionError'); + t.is(test.error.name, 'AssertionError'); t.is(test.title, 'beforeEach for "pass"'); }) .then(function () {