Skip to content

Commit 15f477f

Browse files
author
Thomas
committed
Print out warning in verbose & mini reporter when .only() tests are used
1 parent ce42fcb commit 15f477f

File tree

7 files changed

+105
-13
lines changed

7 files changed

+105
-13
lines changed

lib/colors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ module.exports = {
1010
duration: chalk.gray.dim,
1111
errorStack: chalk.gray,
1212
stack: chalk.red,
13-
failFast: chalk.magenta
13+
information: chalk.magenta
1414
};

lib/reporters/mini.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,16 @@ MiniReporter.prototype.finish = function (runStatus) {
216216
}
217217

218218
if (runStatus.failFastEnabled === true) {
219-
status += '\n\n ' + colors.failFast('`--fail-fast` is on. Any number of tests may have been skipped');
219+
status += '\n\n ' + colors.information('`--fail-fast` is on. Any number of tests may have been skipped');
220+
}
221+
222+
if (runStatus.hasExclusive === true) {
223+
var remainingTests = runStatus.testCount - (runStatus.passCount + runStatus.failCount);
224+
if (remainingTests > 0) {
225+
status += '\n\n ' + colors.information('The .only() modifier is used in some tests. At least', remainingTests, 'tests were not run.');
226+
} else {
227+
status += '\n\n ' + colors.information('The .only() modifier is used in some tests. All other tests have been skipped.');
228+
}
220229
}
221230

222231
return status + '\n\n';

lib/reporters/verbose.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,16 @@ VerboseReporter.prototype.finish = function (runStatus) {
115115
}
116116

117117
if (runStatus.failFastEnabled === true) {
118-
output += '\n\n\n ' + colors.failFast('`--fail-fast` is on. Any number of tests may have been skipped');
118+
output += '\n\n\n ' + colors.information('`--fail-fast` is on. Any number of tests may have been skipped');
119+
}
120+
121+
if (runStatus.hasExclusive === true) {
122+
var remainingTests = runStatus.testCount - (runStatus.passCount + runStatus.failCount);
123+
if (remainingTests > 0) {
124+
output += '\n\n\n ' + colors.information('The .only() modifier is used in some tests. At least', remainingTests, 'tests were not run.');
125+
} else {
126+
output += '\n\n\n ' + colors.information('The .only() modifier is used in some tests. All other tests have been skipped.');
127+
}
119128
}
120129

121130
return output + '\n';

lib/run-status.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,8 @@ class RunStatus extends EventEmitter {
8989
handleStats(stats) {
9090
this.emit('stats', stats, this);
9191

92-
if (this.hasExclusive && !stats.hasExclusive) {
93-
return;
94-
}
95-
96-
if (!this.hasExclusive && stats.hasExclusive) {
92+
if (stats.hasExclusive) {
9793
this.hasExclusive = true;
98-
this.testCount = 0;
9994
}
10095

10196
this.testCount += stats.testCount;

test/api.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ test('Without Pool: test file with exclusive tests causes non-exclusive tests in
3333
return api.run(files)
3434
.then(result => {
3535
t.ok(result.hasExclusive);
36-
t.is(result.testCount, 2);
36+
t.is(result.testCount, 4);
3737
t.is(result.passCount, 2);
3838
t.is(result.failCount, 0);
3939
});
@@ -48,7 +48,7 @@ test('Without Pool: test files can be forced to run in exclusive mode', t => {
4848
{runOnlyExclusive: true}
4949
).then(result => {
5050
t.ok(result.hasExclusive);
51-
t.is(result.testCount, 0);
51+
t.is(result.testCount, 1);
5252
t.is(result.passCount, 0);
5353
t.is(result.failCount, 0);
5454
});

test/reporters/mini.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ test('results when fail-fast is enabled', function (t) {
424424
compareLineOutput(t, output, [
425425
'',
426426
'',
427-
' ' + colors.failFast('`--fail-fast` is on. Any number of tests may have been skipped')
427+
' ' + colors.information('`--fail-fast` is on. Any number of tests may have been skipped')
428428
]);
429429
t.end();
430430
});
@@ -589,3 +589,40 @@ test('stderr and stdout should call _update', function (t) {
589589
reporter._update.restore();
590590
t.end();
591591
});
592+
593+
test('results when hasExclusive is enabled, but there are no known remaining tests', function (t) {
594+
var reporter = miniReporter();
595+
var runStatus = {
596+
hasExclusive: true
597+
};
598+
599+
var output = reporter.finish(runStatus);
600+
compareLineOutput(t, output, [
601+
'',
602+
'',
603+
' ' + colors.information('The .only() modifier is used in some tests. All other tests have been skipped.')
604+
]);
605+
t.end();
606+
});
607+
608+
test('results when hasExclusive is enabled, but there are remaining tests', function (t) {
609+
var reporter = miniReporter();
610+
611+
var runStatus = {
612+
hasExclusive: true,
613+
testCount: 2,
614+
passCount: 1,
615+
failCount: 0
616+
};
617+
618+
var actualOutput = reporter.finish(runStatus);
619+
var expectedOutput = [
620+
'',
621+
'',
622+
' ' + colors.information('The .only() modifier is used in some tests. At least 1 tests were not run.'),
623+
'\n'
624+
].join('\n');
625+
t.is(actualOutput, expectedOutput);
626+
t.end();
627+
});
628+

test/reporters/verbose.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ test('results when fail-fast is enabled', function (t) {
396396
' ' + chalk.red('1 test failed') + time,
397397
'',
398398
'',
399-
' ' + colors.failFast('`--fail-fast` is on. Any number of tests may have been skipped'),
399+
' ' + colors.information('`--fail-fast` is on. Any number of tests may have been skipped'),
400400
''
401401
].join('\n');
402402

@@ -467,6 +467,48 @@ test('reporter.stdout and reporter.stderr both use process.stderr.write', functi
467467
t.end();
468468
});
469469

470+
test('results when hasExclusive is enabled, but there are no known remaining tests', function (t) {
471+
var reporter = verboseReporter();
472+
var runStatus = createRunStatus();
473+
runStatus.hasExclusive = true;
474+
runStatus.passCount = 1;
475+
476+
var output = reporter.finish(runStatus);
477+
var expectedOutput = [
478+
'',
479+
' ' + chalk.green('1 test passed') + time,
480+
'',
481+
'',
482+
' ' + colors.information('The .only() modifier is used in some tests. All other tests have been skipped.'),
483+
''
484+
].join('\n');
485+
486+
t.is(output, expectedOutput);
487+
t.end();
488+
});
489+
490+
test('results when hasExclusive is enabled, but there are remaining tests', function (t) {
491+
var reporter = verboseReporter();
492+
var runStatus = createRunStatus();
493+
runStatus.hasExclusive = true;
494+
runStatus.testCount = 2;
495+
runStatus.passCount = 1;
496+
runStatus.failCount = 0;
497+
498+
var output = reporter.finish(runStatus);
499+
var expectedOutput = [
500+
'',
501+
' ' + chalk.green('1 test passed') + time,
502+
'',
503+
'',
504+
' ' + colors.information('The .only() modifier is used in some tests. At least 1 tests were not run.'),
505+
''
506+
].join('\n');
507+
508+
t.is(output, expectedOutput);
509+
t.end();
510+
});
511+
470512
function fooFunc() {
471513
barFunc();
472514
}

0 commit comments

Comments
 (0)