Skip to content

Commit 23ffce3

Browse files
author
Thomas
committed
Print out warning in verbose & mini reporter when .only() tests are used
1 parent 076eb81 commit 23ffce3

File tree

10 files changed

+116
-14
lines changed

10 files changed

+116
-14
lines changed

lib/colors.js

+1-1
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/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function exit() {
5555

5656
globals.setImmediate(() => {
5757
const hasExclusive = runner.tests.hasExclusive;
58-
const numberOfTests = runner.tests.tests.concurrent.length + runner.tests.tests.serial.length;
58+
const numberOfTests = runner.tests.testCount;
5959

6060
if (numberOfTests === 0) {
6161
send('no-tests', {avaRequired: true});

lib/reporters/mini.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,11 @@ 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 && runStatus.remainingCount > 0) {
223+
status += '\n\n ' + colors.information('The .only() modifier is used in some tests.', runStatus.remainingCount, 'test(s) were not run.');
220224
}
221225

222226
return status + '\n\n';

lib/reporters/verbose.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ 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 && runStatus.remainingCount > 0) {
122+
output += '\n\n\n ' + colors.information('The .only() modifier is used in some tests.', runStatus.remainingCount, 'test(s) were not run.');
119123
}
120124

121125
return output + '\n';

lib/run-status.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class RunStatus extends EventEmitter {
4545
this.failCount = 0;
4646
this.fileCount = 0;
4747
this.testCount = 0;
48+
this.remainingCount = 0;
4849
this.previousFailCount = 0;
4950
this.knownFailures = [];
5051
this.errors = [];
@@ -89,13 +90,8 @@ class RunStatus extends EventEmitter {
8990
handleStats(stats) {
9091
this.emit('stats', stats, this);
9192

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

10197
this.testCount += stats.testCount;
@@ -139,6 +135,7 @@ class RunStatus extends EventEmitter {
139135
this.skipCount = sum(this.stats, 'skipCount');
140136
this.todoCount = sum(this.stats, 'todoCount');
141137
this.failCount = sum(this.stats, 'failCount');
138+
this.remainingCount = this.testCount - this.passCount - this.failCount - this.skipCount - this.todoCount - this.knownFailureCount;
142139
}
143140
}
144141

lib/test-collection.js

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class TestCollection extends EventEmitter {
1010
super();
1111

1212
this.hasExclusive = false;
13+
this.testCount = 0;
1314

1415
this.tests = {
1516
concurrent: [],
@@ -66,6 +67,8 @@ class TestCollection extends EventEmitter {
6667
return;
6768
}
6869

70+
this.testCount++;
71+
6972
// Add `.only()` tests if `.only()` was used previously
7073
if (this.hasExclusive && !metadata.exclusive) {
7174
return;

test/api.js

+2-2
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, 5);
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

+34-1
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,36 @@ 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+
t.is(output, '\n\n');
601+
t.end();
602+
});
603+
604+
test('results when hasExclusive is enabled, but there are remaining tests', function (t) {
605+
var reporter = miniReporter();
606+
607+
var runStatus = {
608+
hasExclusive: true,
609+
testCount: 2,
610+
passCount: 1,
611+
remainingCount: 1
612+
};
613+
614+
var actualOutput = reporter.finish(runStatus);
615+
var expectedOutput = [
616+
'',
617+
'',
618+
' ' + colors.information('The .only() modifier is used in some tests. 1 test(s) were not run.'),
619+
'\n'
620+
].join('\n');
621+
t.is(actualOutput, expectedOutput);
622+
t.end();
623+
});
624+

test/reporters/verbose.js

+41-1
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,46 @@ 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+
].join('\n');
482+
483+
t.is(output, expectedOutput);
484+
t.end();
485+
});
486+
487+
test('results when hasExclusive is enabled, but there are remaining tests', function (t) {
488+
var reporter = verboseReporter();
489+
var runStatus = createRunStatus();
490+
runStatus.hasExclusive = true;
491+
runStatus.testCount = 2;
492+
runStatus.passCount = 1;
493+
runStatus.failCount = 0;
494+
runStatus.remainingCount = 1;
495+
496+
var output = reporter.finish(runStatus);
497+
var expectedOutput = [
498+
'',
499+
' ' + chalk.green('1 test passed') + time,
500+
'',
501+
'',
502+
' ' + colors.information('The .only() modifier is used in some tests. 1 test(s) were not run.'),
503+
''
504+
].join('\n');
505+
506+
t.is(output, expectedOutput);
507+
t.end();
508+
});
509+
470510
function fooFunc() {
471511
barFunc();
472512
}

test/run-status.js

+21
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,24 @@ test('successfully initializes without any options provided', t => {
6666
t.is(runStatus.base, '');
6767
t.end();
6868
});
69+
70+
test('calculate remaining test count', t => {
71+
const runStatus = new RunStatus();
72+
runStatus.testCount = 10;
73+
74+
var results = [{
75+
stats: {
76+
passCount: 1,
77+
failCount: 1,
78+
skipCount: 1,
79+
todoCount: 1,
80+
knownFailureCount: 1
81+
}
82+
}];
83+
84+
runStatus.processResults(results);
85+
86+
t.is(runStatus.remainingCount, 5);
87+
t.end();
88+
});
89+

0 commit comments

Comments
 (0)