Skip to content

Commit

Permalink
don't display test title, if there's only one anonymous test
Browse files Browse the repository at this point in the history
  • Loading branch information
vdemedes committed Nov 1, 2015
1 parent c2f4c9f commit bb1304c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var cli = meow({
]
});

var testCount = 0;
var fileCount = 0;
var errors = [];

Expand Down Expand Up @@ -75,6 +76,10 @@ function prefixTitle(file) {
return prefix;
}

function stats(stats) {
testCount += stats.testCount;
}

function test(data) {
var isError = data.err.message;

Expand All @@ -89,6 +94,12 @@ function test(data) {

errors.push(data);
} else {
// if there's only one file and one anonymous test
// don't log it
if (fileCount === 1 && testCount === 1 && data.title === '[anonymous]') {
return;
}

log.test(null, prefix + data.title, data.duration);
}
}
Expand All @@ -105,6 +116,7 @@ function run(file) {
}

return fork(args)
.on('stats', stats)
.on('test', test)
.on('data', function (data) {
process.stdout.write(data);
Expand Down
8 changes: 8 additions & 0 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ Runner.prototype.run = function () {
var tests = this.tests;
var stats = this.stats;

// Runner is executed directly in tests, in that case process.send() == undefined
if (process.send) {
process.send({
name: 'stats',
data: stats
});
}

return eachSeries(tests.before, this._runTest.bind(this))
.catch(noop)
.then(function () {
Expand Down
11 changes: 11 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,17 @@ test('display test title prefixes', function (t) {
});
});

test('don\'t display test title, if there is only one anonymous test', function (t) {
t.plan(2);

execCli(['fixture/es2015.js'], function (err, stdout, stderr) {
t.ifError(err);

t.is(stderr.trim(), '1 test passed');
t.end();
});
});

test('fail-fast mode', function (t) {
t.plan(5);

Expand Down

0 comments on commit bb1304c

Please sign in to comment.