Skip to content

Commit

Permalink
Print out warning in verbose & mini reporter when .only() tests are used
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas authored and novemberborn committed Jan 15, 2017
1 parent fb10c4f commit 22a6081
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ module.exports = {
duration: chalk.gray.dim,
errorStack: chalk.gray,
stack: chalk.red,
failFast: chalk.magenta
information: chalk.magenta
};
2 changes: 1 addition & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function exit() {

globals.setImmediate(() => {
const hasExclusive = runner.tests.hasExclusive;
const numberOfTests = runner.tests.tests.concurrent.length + runner.tests.tests.serial.length;
const numberOfTests = runner.tests.testCount;

if (numberOfTests === 0) {
send('no-tests', {avaRequired: true});
Expand Down
6 changes: 5 additions & 1 deletion lib/reporters/mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ MiniReporter.prototype.finish = function (runStatus) {
}

if (runStatus.failFastEnabled === true) {
status += '\n\n ' + colors.failFast('`--fail-fast` is on. Any number of tests may have been skipped');
status += '\n\n ' + colors.information('`--fail-fast` is on. Any number of tests may have been skipped');
}

if (runStatus.hasExclusive === true && runStatus.remainingCount > 0) {
status += '\n\n ' + colors.information('The .only() modifier is used in some tests.', runStatus.remainingCount, plur('test', runStatus.remainingCount), plur('was', 'were', runStatus.remainingCount), 'not run.');
}

return status + '\n\n';
Expand Down
6 changes: 5 additions & 1 deletion lib/reporters/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ VerboseReporter.prototype.finish = function (runStatus) {
}

if (runStatus.failFastEnabled === true) {
output += '\n\n\n ' + colors.failFast('`--fail-fast` is on. Any number of tests may have been skipped');
output += '\n\n\n ' + colors.information('`--fail-fast` is on. Any number of tests may have been skipped');
}

if (runStatus.hasExclusive === true && runStatus.remainingCount > 0) {
output += '\n\n\n ' + colors.information('The .only() modifier is used in some tests.', runStatus.remainingCount, plur('test', runStatus.remainingCount), plur('was', 'were', runStatus.remainingCount), 'not run.');
}

return output + '\n';
Expand Down
9 changes: 3 additions & 6 deletions lib/run-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class RunStatus extends EventEmitter {
this.failCount = 0;
this.fileCount = 0;
this.testCount = 0;
this.remainingCount = 0;
this.previousFailCount = 0;
this.knownFailures = [];
this.errors = [];
Expand Down Expand Up @@ -89,13 +90,8 @@ class RunStatus extends EventEmitter {
handleStats(stats) {
this.emit('stats', stats, this);

if (this.hasExclusive && !stats.hasExclusive) {
return;
}

if (!this.hasExclusive && stats.hasExclusive) {
if (stats.hasExclusive) {
this.hasExclusive = true;
this.testCount = 0;
}

this.testCount += stats.testCount;
Expand Down Expand Up @@ -139,6 +135,7 @@ class RunStatus extends EventEmitter {
this.skipCount = sum(this.stats, 'skipCount');
this.todoCount = sum(this.stats, 'todoCount');
this.failCount = sum(this.stats, 'failCount');
this.remainingCount = this.testCount - this.passCount - this.failCount - this.skipCount - this.todoCount - this.knownFailureCount;
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/test-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class TestCollection extends EventEmitter {
super();

this.hasExclusive = false;
this.testCount = 0;

this.tests = {
concurrent: [],
Expand Down Expand Up @@ -66,6 +67,8 @@ class TestCollection extends EventEmitter {
return;
}

this.testCount++;

// Add `.only()` tests if `.only()` was used previously
if (this.hasExclusive && !metadata.exclusive) {
return;
Expand Down
4 changes: 2 additions & 2 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test('Without Pool: test file with exclusive tests causes non-exclusive tests in
return api.run(files)
.then(result => {
t.ok(result.hasExclusive);
t.is(result.testCount, 2);
t.is(result.testCount, 5);
t.is(result.passCount, 2);
t.is(result.failCount, 0);
});
Expand All @@ -48,7 +48,7 @@ test('Without Pool: test files can be forced to run in exclusive mode', t => {
{runOnlyExclusive: true}
).then(result => {
t.ok(result.hasExclusive);
t.is(result.testCount, 0);
t.is(result.testCount, 1);
t.is(result.passCount, 0);
t.is(result.failCount, 0);
});
Expand Down
56 changes: 55 additions & 1 deletion test/reporters/mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ test('results when fail-fast is enabled', function (t) {
compareLineOutput(t, output, [
'',
'',
' ' + colors.failFast('`--fail-fast` is on. Any number of tests may have been skipped')
' ' + colors.information('`--fail-fast` is on. Any number of tests may have been skipped')
]);
t.end();
});
Expand Down Expand Up @@ -589,3 +589,57 @@ test('stderr and stdout should call _update', function (t) {
reporter._update.restore();
t.end();
});

test('results when hasExclusive is enabled, but there are no known remaining tests', function (t) {
var reporter = miniReporter();
var runStatus = {
hasExclusive: true
};

var output = reporter.finish(runStatus);
t.is(output, '\n\n');
t.end();
});

test('results when hasExclusive is enabled, but there is one remaining tests', function (t) {
var reporter = miniReporter();

var runStatus = {
hasExclusive: true,
testCount: 2,
passCount: 1,
remainingCount: 1
};

var actualOutput = reporter.finish(runStatus);
var expectedOutput = [
'',
'',
' ' + colors.information('The .only() modifier is used in some tests. 1 test was not run.'),
'\n'
].join('\n');
t.is(actualOutput, expectedOutput);
t.end();
});

test('results when hasExclusive is enabled, but there are multiple remaining tests', function (t) {
var reporter = miniReporter();

var runStatus = {
hasExclusive: true,
testCount: 3,
passCount: 1,
remainingCount: 2
};

var actualOutput = reporter.finish(runStatus);
var expectedOutput = [
'',
'',
' ' + colors.information('The .only() modifier is used in some tests. 2 tests were not run.'),
'\n'
].join('\n');
t.is(actualOutput, expectedOutput);
t.end();
});

65 changes: 64 additions & 1 deletion test/reporters/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ test('results when fail-fast is enabled', function (t) {
' ' + chalk.red('1 test failed') + time,
'',
'',
' ' + colors.failFast('`--fail-fast` is on. Any number of tests may have been skipped'),
' ' + colors.information('`--fail-fast` is on. Any number of tests may have been skipped'),
''
].join('\n');

Expand Down Expand Up @@ -467,6 +467,69 @@ test('reporter.stdout and reporter.stderr both use process.stderr.write', functi
t.end();
});

test('results when hasExclusive is enabled, but there are no known remaining tests', function (t) {
var reporter = verboseReporter();
var runStatus = createRunStatus();
runStatus.hasExclusive = true;
runStatus.passCount = 1;

var output = reporter.finish(runStatus);
var expectedOutput = [
'',
' ' + chalk.green('1 test passed') + time,
''
].join('\n');

t.is(output, expectedOutput);
t.end();
});

test('results when hasExclusive is enabled, but there is one remaining tests', function (t) {
var reporter = verboseReporter();
var runStatus = createRunStatus();
runStatus.hasExclusive = true;
runStatus.testCount = 2;
runStatus.passCount = 1;
runStatus.failCount = 0;
runStatus.remainingCount = 1;

var output = reporter.finish(runStatus);
var expectedOutput = [
'',
' ' + chalk.green('1 test passed') + time,
'',
'',
' ' + colors.information('The .only() modifier is used in some tests. 1 test was not run.'),
''
].join('\n');

t.is(output, expectedOutput);
t.end();
});

test('results when hasExclusive is enabled, but there are multiple remaining tests', function (t) {
var reporter = verboseReporter();
var runStatus = createRunStatus();
runStatus.hasExclusive = true;
runStatus.testCount = 3;
runStatus.passCount = 1;
runStatus.failCount = 0;
runStatus.remainingCount = 2;

var output = reporter.finish(runStatus);
var expectedOutput = [
'',
' ' + chalk.green('1 test passed') + time,
'',
'',
' ' + colors.information('The .only() modifier is used in some tests. 2 tests were not run.'),
''
].join('\n');

t.is(output, expectedOutput);
t.end();
});

function fooFunc() {
barFunc();
}
Expand Down
21 changes: 21 additions & 0 deletions test/run-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,24 @@ test('successfully initializes without any options provided', t => {
t.is(runStatus.base, '');
t.end();
});

test('calculate remaining test count', t => {
const runStatus = new RunStatus();
runStatus.testCount = 10;

var results = [{
stats: {
passCount: 1,
failCount: 1,
skipCount: 1,
todoCount: 1,
knownFailureCount: 1
}
}];

runStatus.processResults(results);

t.is(runStatus.remainingCount, 5);
t.end();
});

0 comments on commit 22a6081

Please sign in to comment.