Skip to content

Commit e825faf

Browse files
committed
Print number of skipped test files when --fail-fast is used
1 parent 54b9518 commit e825faf

File tree

6 files changed

+185
-11
lines changed

6 files changed

+185
-11
lines changed

api.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class Api extends EventEmitter {
8888
prefixTitles: apiOptions.explicitTitles || files.length > 1,
8989
base: path.relative(process.cwd(), commonPathPrefix(files)) + path.sep,
9090
failFast,
91+
fileCount: files.length,
9192
updateSnapshots: runtimeOptions.updateSnapshots
9293
});
9394

lib/reporters/mini.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,22 @@ class MiniReporter {
249249
});
250250
}
251251

252-
if (runStatus.failFastEnabled === true && runStatus.remainingCount > 0 && runStatus.failCount > 0) {
253-
const remaining = 'At least ' + runStatus.remainingCount + ' ' + plur('test was', 'tests were', runStatus.remainingCount) + ' skipped.';
254-
status += ' ' + colors.information('`--fail-fast` is on. ' + remaining) + '\n\n';
252+
if (runStatus.failFastEnabled === true && runStatus.failCount > 0 && (runStatus.remainingCount > 0 || runStatus.fileCount > runStatus.observationCount)) {
253+
let remaining = '';
254+
if (runStatus.remainingCount > 0) {
255+
remaining += `At least ${runStatus.remainingCount} ${plur('test was', 'tests were', runStatus.remainingCount)} skipped`;
256+
if (runStatus.fileCount > runStatus.observationCount) {
257+
remaining += ', as well as ';
258+
}
259+
}
260+
if (runStatus.fileCount > runStatus.observationCount) {
261+
const skippedFileCount = runStatus.fileCount - runStatus.observationCount;
262+
remaining += `${skippedFileCount} ${plur('test file', 'test files', skippedFileCount)}`;
263+
if (runStatus.remainingCount === 0) {
264+
remaining += ` ${plur('was', 'were', skippedFileCount)} skipped`;
265+
}
266+
}
267+
status += ' ' + colors.information('`--fail-fast` is on. ' + remaining + '.') + '\n\n';
255268
}
256269

257270
if (runStatus.hasExclusive === true && runStatus.remainingCount > 0) {

lib/reporters/verbose.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,22 @@ class VerboseReporter {
166166
});
167167
}
168168

169-
if (runStatus.failFastEnabled === true && runStatus.remainingCount > 0 && runStatus.failCount > 0) {
170-
const remaining = 'At least ' + runStatus.remainingCount + ' ' + plur('test was', 'tests were', runStatus.remainingCount) + ' skipped.';
171-
output += ' ' + colors.information('`--fail-fast` is on. ' + remaining) + '\n\n';
169+
if (runStatus.failFastEnabled === true && runStatus.failCount > 0 && (runStatus.remainingCount > 0 || runStatus.fileCount > runStatus.observationCount)) {
170+
let remaining = '';
171+
if (runStatus.remainingCount > 0) {
172+
remaining += `At least ${runStatus.remainingCount} ${plur('test was', 'tests were', runStatus.remainingCount)} skipped`;
173+
if (runStatus.fileCount > runStatus.observationCount) {
174+
remaining += ', as well as ';
175+
}
176+
}
177+
if (runStatus.fileCount > runStatus.observationCount) {
178+
const skippedFileCount = runStatus.fileCount - runStatus.observationCount;
179+
remaining += `${skippedFileCount} ${plur('test file', 'test files', skippedFileCount)}`;
180+
if (runStatus.remainingCount === 0) {
181+
remaining += ` ${plur('was', 'were', skippedFileCount)} skipped`;
182+
}
183+
}
184+
output += ' ' + colors.information('`--fail-fast` is on. ' + remaining + '.') + '\n\n';
172185
}
173186

174187
if (runStatus.hasExclusive === true && runStatus.remainingCount > 0) {

lib/run-status.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class RunStatus extends EventEmitter {
3131
this.skipCount = 0;
3232
this.todoCount = 0;
3333
this.failCount = 0;
34-
this.fileCount = 0;
34+
this.fileCount = opts.fileCount || 0;
3535
this.testCount = 0;
3636
this.remainingCount = 0;
3737
this.previousFailCount = 0;
@@ -41,11 +41,13 @@ class RunStatus extends EventEmitter {
4141
this.tests = [];
4242
this.failFastEnabled = opts.failFast || false;
4343
this.updateSnapshots = opts.updateSnapshots || false;
44+
this.observationCount = 0;
4445

4546
autoBind(this);
4647
}
4748

4849
observeFork(emitter) {
50+
this.observationCount++;
4951
emitter
5052
.on('teardown', this.handleTeardown)
5153
.on('stats', this.handleStats)

test/reporters/mini.js

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,9 @@ test('results when fail-fast is enabled', t => {
649649
const runStatus = {
650650
remainingCount: 1,
651651
failCount: 1,
652-
failFastEnabled: true
652+
failFastEnabled: true,
653+
fileCount: 1,
654+
observationCount: 1
653655
};
654656

655657
const output = reporter.finish(runStatus);
@@ -666,7 +668,9 @@ test('results when fail-fast is enabled with multiple skipped tests', t => {
666668
const runStatus = {
667669
remainingCount: 2,
668670
failCount: 1,
669-
failFastEnabled: true
671+
failFastEnabled: true,
672+
fileCount: 1,
673+
observationCount: 1
670674
};
671675

672676
const output = reporter.finish(runStatus);
@@ -678,12 +682,71 @@ test('results when fail-fast is enabled with multiple skipped tests', t => {
678682
t.end();
679683
});
680684

685+
test('results when fail-fast is enabled with skipped test file', t => {
686+
const reporter = miniReporter();
687+
const runStatus = {
688+
remainingCount: 0,
689+
failCount: 1,
690+
failFastEnabled: true,
691+
fileCount: 2,
692+
observationCount: 1
693+
};
694+
695+
const output = reporter.finish(runStatus);
696+
compareLineOutput(t, output, [
697+
'',
698+
' ' + colors.magenta('`--fail-fast` is on. 1 test file was skipped.'),
699+
''
700+
]);
701+
t.end();
702+
});
703+
704+
test('results when fail-fast is enabled with multiple skipped test files', t => {
705+
const reporter = miniReporter();
706+
const runStatus = {
707+
remainingCount: 0,
708+
failCount: 1,
709+
failFastEnabled: true,
710+
fileCount: 3,
711+
observationCount: 1
712+
};
713+
714+
const output = reporter.finish(runStatus);
715+
compareLineOutput(t, output, [
716+
'',
717+
' ' + colors.magenta('`--fail-fast` is on. 2 test files were skipped.'),
718+
''
719+
]);
720+
t.end();
721+
});
722+
723+
test('results when fail-fast is enabled with skipped tests and files', t => {
724+
const reporter = miniReporter();
725+
const runStatus = {
726+
remainingCount: 1,
727+
failCount: 1,
728+
failFastEnabled: true,
729+
fileCount: 3,
730+
observationCount: 1
731+
};
732+
733+
const output = reporter.finish(runStatus);
734+
compareLineOutput(t, output, [
735+
'',
736+
' ' + colors.magenta('`--fail-fast` is on. At least 1 test was skipped, as well as 2 test files.'),
737+
''
738+
]);
739+
t.end();
740+
});
741+
681742
test('results without fail-fast if no failing tests', t => {
682743
const reporter = miniReporter();
683744
const runStatus = {
684745
remainingCount: 1,
685746
failCount: 0,
686-
failFastEnabled: true
747+
failFastEnabled: true,
748+
fileCount: 1,
749+
observationCount: 1
687750
};
688751

689752
const output = reporter.finish(runStatus);
@@ -696,7 +759,9 @@ test('results without fail-fast if no skipped tests', t => {
696759
const runStatus = {
697760
remainingCount: 0,
698761
failCount: 1,
699-
failFastEnabled: true
762+
failFastEnabled: true,
763+
fileCount: 1,
764+
observationCount: 1
700765
};
701766

702767
const output = reporter.finish(runStatus);

test/reporters/verbose.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ test('results when fail-fast is enabled', t => {
594594
runStatus.remainingCount = 1;
595595
runStatus.failCount = 1;
596596
runStatus.failFastEnabled = true;
597+
runStatus.fileCount = 1;
598+
runStatus.observationCount = 1;
597599
runStatus.tests = [{
598600
title: 'failed test'
599601
}];
@@ -616,6 +618,8 @@ test('results when fail-fast is enabled with multiple skipped tests', t => {
616618
runStatus.remainingCount = 2;
617619
runStatus.failCount = 1;
618620
runStatus.failFastEnabled = true;
621+
runStatus.fileCount = 1;
622+
runStatus.observationCount = 1;
619623
runStatus.tests = [{
620624
title: 'failed test'
621625
}];
@@ -632,13 +636,87 @@ test('results when fail-fast is enabled with multiple skipped tests', t => {
632636
t.end();
633637
});
634638

639+
test('results when fail-fast is enabled with skipped test file', t => {
640+
const reporter = createReporter();
641+
const runStatus = createRunStatus();
642+
runStatus.remainingCount = 0;
643+
runStatus.failCount = 1;
644+
runStatus.failFastEnabled = true;
645+
runStatus.fileCount = 2;
646+
runStatus.observationCount = 1;
647+
runStatus.tests = [{
648+
title: 'failed test'
649+
}];
650+
651+
const output = reporter.finish(runStatus);
652+
const expectedOutput = [
653+
'\n ' + colors.red('1 test failed'),
654+
'\n',
655+
'\n ' + colors.magenta('`--fail-fast` is on. 1 test file was skipped.'),
656+
'\n'
657+
].join('');
658+
659+
t.is(output, expectedOutput);
660+
t.end();
661+
});
662+
663+
test('results when fail-fast is enabled with multiple skipped test files', t => {
664+
const reporter = createReporter();
665+
const runStatus = createRunStatus();
666+
runStatus.remainingCount = 0;
667+
runStatus.failCount = 1;
668+
runStatus.failFastEnabled = true;
669+
runStatus.fileCount = 3;
670+
runStatus.observationCount = 1;
671+
runStatus.tests = [{
672+
title: 'failed test'
673+
}];
674+
675+
const output = reporter.finish(runStatus);
676+
const expectedOutput = [
677+
'\n ' + colors.red('1 test failed'),
678+
'\n',
679+
'\n ' + colors.magenta('`--fail-fast` is on. 2 test files were skipped.'),
680+
'\n'
681+
].join('');
682+
683+
t.is(output, expectedOutput);
684+
t.end();
685+
});
686+
687+
test('results when fail-fast is enabled with skipped tests and files', t => {
688+
const reporter = createReporter();
689+
const runStatus = createRunStatus();
690+
runStatus.remainingCount = 1;
691+
runStatus.failCount = 1;
692+
runStatus.failFastEnabled = true;
693+
runStatus.fileCount = 3;
694+
runStatus.observationCount = 1;
695+
runStatus.tests = [{
696+
title: 'failed test'
697+
}];
698+
699+
const output = reporter.finish(runStatus);
700+
const expectedOutput = [
701+
'\n ' + colors.red('1 test failed'),
702+
'\n',
703+
'\n ' + colors.magenta('`--fail-fast` is on. At least 1 test was skipped, as well as 2 test files.'),
704+
'\n'
705+
].join('');
706+
707+
t.is(output, expectedOutput);
708+
t.end();
709+
});
710+
635711
test('results without fail-fast if no failing tests', t => {
636712
const reporter = createReporter();
637713
const runStatus = createRunStatus();
638714
runStatus.remainingCount = 1;
639715
runStatus.failCount = 0;
640716
runStatus.passCount = 1;
641717
runStatus.failFastEnabled = true;
718+
runStatus.fileCount = 1;
719+
runStatus.observationCount = 1;
642720

643721
const output = reporter.finish(runStatus);
644722
const expectedOutput = [
@@ -657,6 +735,8 @@ test('results without fail-fast if no skipped tests', t => {
657735
runStatus.remainingCount = 0;
658736
runStatus.failCount = 1;
659737
runStatus.failFastEnabled = true;
738+
runStatus.fileCount = 1;
739+
runStatus.observationCount = 1;
660740
runStatus.tests = [{
661741
title: 'failed test'
662742
}];

0 commit comments

Comments
 (0)