From 8de263010aa0ccf72a0e859070f02b1103837577 Mon Sep 17 00:00:00 2001 From: Mark Wubben Date: Tue, 6 Feb 2018 17:33:12 +0000 Subject: [PATCH] Print number of skipped test files when --fail-fast is used --- api.js | 1 + lib/reporters/mini.js | 19 ++++++++-- lib/reporters/verbose.js | 19 ++++++++-- lib/run-status.js | 4 +- test/reporters/mini.js | 73 +++++++++++++++++++++++++++++++++-- test/reporters/verbose.js | 80 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 185 insertions(+), 11 deletions(-) diff --git a/api.js b/api.js index d3c583244..4bf3a63f7 100644 --- a/api.js +++ b/api.js @@ -88,6 +88,7 @@ class Api extends EventEmitter { prefixTitles: apiOptions.explicitTitles || files.length > 1, base: path.relative(process.cwd(), commonPathPrefix(files)) + path.sep, failFast, + fileCount: files.length, updateSnapshots: runtimeOptions.updateSnapshots }); diff --git a/lib/reporters/mini.js b/lib/reporters/mini.js index 1619b2c3d..5dae12ff8 100644 --- a/lib/reporters/mini.js +++ b/lib/reporters/mini.js @@ -249,9 +249,22 @@ class MiniReporter { }); } - if (runStatus.failFastEnabled === true && runStatus.remainingCount > 0 && runStatus.failCount > 0) { - const remaining = 'At least ' + runStatus.remainingCount + ' ' + plur('test was', 'tests were', runStatus.remainingCount) + ' skipped.'; - status += ' ' + colors.information('`--fail-fast` is on. ' + remaining) + '\n\n'; + if (runStatus.failFastEnabled === true && runStatus.failCount > 0 && (runStatus.remainingCount > 0 || runStatus.fileCount > runStatus.observationCount)) { + let remaining = ''; + if (runStatus.remainingCount > 0) { + remaining += `At least ${runStatus.remainingCount} ${plur('test was', 'tests were', runStatus.remainingCount)} skipped`; + if (runStatus.fileCount > runStatus.observationCount) { + remaining += ', as well as '; + } + } + if (runStatus.fileCount > runStatus.observationCount) { + const skippedFileCount = runStatus.fileCount - runStatus.observationCount; + remaining += `${skippedFileCount} ${plur('test file', 'test files', skippedFileCount)}`; + if (runStatus.remainingCount === 0) { + remaining += ` ${plur('was', 'were', skippedFileCount)} skipped`; + } + } + status += ' ' + colors.information('`--fail-fast` is on. ' + remaining + '.') + '\n\n'; } if (runStatus.hasExclusive === true && runStatus.remainingCount > 0) { diff --git a/lib/reporters/verbose.js b/lib/reporters/verbose.js index 1d81ae5b8..d0083c8fe 100644 --- a/lib/reporters/verbose.js +++ b/lib/reporters/verbose.js @@ -166,9 +166,22 @@ class VerboseReporter { }); } - if (runStatus.failFastEnabled === true && runStatus.remainingCount > 0 && runStatus.failCount > 0) { - const remaining = 'At least ' + runStatus.remainingCount + ' ' + plur('test was', 'tests were', runStatus.remainingCount) + ' skipped.'; - output += ' ' + colors.information('`--fail-fast` is on. ' + remaining) + '\n\n'; + if (runStatus.failFastEnabled === true && runStatus.failCount > 0 && (runStatus.remainingCount > 0 || runStatus.fileCount > runStatus.observationCount)) { + let remaining = ''; + if (runStatus.remainingCount > 0) { + remaining += `At least ${runStatus.remainingCount} ${plur('test was', 'tests were', runStatus.remainingCount)} skipped`; + if (runStatus.fileCount > runStatus.observationCount) { + remaining += ', as well as '; + } + } + if (runStatus.fileCount > runStatus.observationCount) { + const skippedFileCount = runStatus.fileCount - runStatus.observationCount; + remaining += `${skippedFileCount} ${plur('test file', 'test files', skippedFileCount)}`; + if (runStatus.remainingCount === 0) { + remaining += ` ${plur('was', 'were', skippedFileCount)} skipped`; + } + } + output += ' ' + colors.information('`--fail-fast` is on. ' + remaining + '.') + '\n\n'; } if (runStatus.hasExclusive === true && runStatus.remainingCount > 0) { diff --git a/lib/run-status.js b/lib/run-status.js index 461ab8f90..aae0367c8 100644 --- a/lib/run-status.js +++ b/lib/run-status.js @@ -31,7 +31,7 @@ class RunStatus extends EventEmitter { this.skipCount = 0; this.todoCount = 0; this.failCount = 0; - this.fileCount = 0; + this.fileCount = opts.fileCount || 0; this.testCount = 0; this.remainingCount = 0; this.previousFailCount = 0; @@ -41,11 +41,13 @@ class RunStatus extends EventEmitter { this.tests = []; this.failFastEnabled = opts.failFast || false; this.updateSnapshots = opts.updateSnapshots || false; + this.observationCount = 0; autoBind(this); } observeFork(emitter) { + this.observationCount++; emitter .on('teardown', this.handleTeardown) .on('stats', this.handleStats) diff --git a/test/reporters/mini.js b/test/reporters/mini.js index a45705795..3d62a1d2e 100644 --- a/test/reporters/mini.js +++ b/test/reporters/mini.js @@ -649,7 +649,9 @@ test('results when fail-fast is enabled', t => { const runStatus = { remainingCount: 1, failCount: 1, - failFastEnabled: true + failFastEnabled: true, + fileCount: 1, + observationCount: 1 }; const output = reporter.finish(runStatus); @@ -666,7 +668,9 @@ test('results when fail-fast is enabled with multiple skipped tests', t => { const runStatus = { remainingCount: 2, failCount: 1, - failFastEnabled: true + failFastEnabled: true, + fileCount: 1, + observationCount: 1 }; const output = reporter.finish(runStatus); @@ -678,12 +682,71 @@ test('results when fail-fast is enabled with multiple skipped tests', t => { t.end(); }); +test('results when fail-fast is enabled with skipped test file', t => { + const reporter = miniReporter(); + const runStatus = { + remainingCount: 0, + failCount: 1, + failFastEnabled: true, + fileCount: 2, + observationCount: 1 + }; + + const output = reporter.finish(runStatus); + compareLineOutput(t, output, [ + '', + ' ' + colors.magenta('`--fail-fast` is on. 1 test file was skipped.'), + '' + ]); + t.end(); +}); + +test('results when fail-fast is enabled with multiple skipped test files', t => { + const reporter = miniReporter(); + const runStatus = { + remainingCount: 0, + failCount: 1, + failFastEnabled: true, + fileCount: 3, + observationCount: 1 + }; + + const output = reporter.finish(runStatus); + compareLineOutput(t, output, [ + '', + ' ' + colors.magenta('`--fail-fast` is on. 2 test files were skipped.'), + '' + ]); + t.end(); +}); + +test('results when fail-fast is enabled with skipped tests and files', t => { + const reporter = miniReporter(); + const runStatus = { + remainingCount: 1, + failCount: 1, + failFastEnabled: true, + fileCount: 3, + observationCount: 1 + }; + + const output = reporter.finish(runStatus); + compareLineOutput(t, output, [ + '', + ' ' + colors.magenta('`--fail-fast` is on. At least 1 test was skipped, as well as 2 test files.'), + '' + ]); + t.end(); +}); + test('results without fail-fast if no failing tests', t => { const reporter = miniReporter(); const runStatus = { remainingCount: 1, failCount: 0, - failFastEnabled: true + failFastEnabled: true, + fileCount: 1, + observationCount: 1 }; const output = reporter.finish(runStatus); @@ -696,7 +759,9 @@ test('results without fail-fast if no skipped tests', t => { const runStatus = { remainingCount: 0, failCount: 1, - failFastEnabled: true + failFastEnabled: true, + fileCount: 1, + observationCount: 1 }; const output = reporter.finish(runStatus); diff --git a/test/reporters/verbose.js b/test/reporters/verbose.js index 4961cef1f..c12073060 100644 --- a/test/reporters/verbose.js +++ b/test/reporters/verbose.js @@ -594,6 +594,8 @@ test('results when fail-fast is enabled', t => { runStatus.remainingCount = 1; runStatus.failCount = 1; runStatus.failFastEnabled = true; + runStatus.fileCount = 1; + runStatus.observationCount = 1; runStatus.tests = [{ title: 'failed test' }]; @@ -616,6 +618,8 @@ test('results when fail-fast is enabled with multiple skipped tests', t => { runStatus.remainingCount = 2; runStatus.failCount = 1; runStatus.failFastEnabled = true; + runStatus.fileCount = 1; + runStatus.observationCount = 1; runStatus.tests = [{ title: 'failed test' }]; @@ -632,6 +636,78 @@ test('results when fail-fast is enabled with multiple skipped tests', t => { t.end(); }); +test('results when fail-fast is enabled with skipped test file', t => { + const reporter = createReporter(); + const runStatus = createRunStatus(); + runStatus.remainingCount = 0; + runStatus.failCount = 1; + runStatus.failFastEnabled = true; + runStatus.fileCount = 2; + runStatus.observationCount = 1; + runStatus.tests = [{ + title: 'failed test' + }]; + + const output = reporter.finish(runStatus); + const expectedOutput = [ + '\n ' + colors.red('1 test failed'), + '\n', + '\n ' + colors.magenta('`--fail-fast` is on. 1 test file was skipped.'), + '\n' + ].join(''); + + t.is(output, expectedOutput); + t.end(); +}); + +test('results when fail-fast is enabled with multiple skipped test files', t => { + const reporter = createReporter(); + const runStatus = createRunStatus(); + runStatus.remainingCount = 0; + runStatus.failCount = 1; + runStatus.failFastEnabled = true; + runStatus.fileCount = 3; + runStatus.observationCount = 1; + runStatus.tests = [{ + title: 'failed test' + }]; + + const output = reporter.finish(runStatus); + const expectedOutput = [ + '\n ' + colors.red('1 test failed'), + '\n', + '\n ' + colors.magenta('`--fail-fast` is on. 2 test files were skipped.'), + '\n' + ].join(''); + + t.is(output, expectedOutput); + t.end(); +}); + +test('results when fail-fast is enabled with skipped tests and files', t => { + const reporter = createReporter(); + const runStatus = createRunStatus(); + runStatus.remainingCount = 1; + runStatus.failCount = 1; + runStatus.failFastEnabled = true; + runStatus.fileCount = 3; + runStatus.observationCount = 1; + runStatus.tests = [{ + title: 'failed test' + }]; + + const output = reporter.finish(runStatus); + const expectedOutput = [ + '\n ' + colors.red('1 test failed'), + '\n', + '\n ' + colors.magenta('`--fail-fast` is on. At least 1 test was skipped, as well as 2 test files.'), + '\n' + ].join(''); + + t.is(output, expectedOutput); + t.end(); +}); + test('results without fail-fast if no failing tests', t => { const reporter = createReporter(); const runStatus = createRunStatus(); @@ -639,6 +715,8 @@ test('results without fail-fast if no failing tests', t => { runStatus.failCount = 0; runStatus.passCount = 1; runStatus.failFastEnabled = true; + runStatus.fileCount = 1; + runStatus.observationCount = 1; const output = reporter.finish(runStatus); const expectedOutput = [ @@ -657,6 +735,8 @@ test('results without fail-fast if no skipped tests', t => { runStatus.remainingCount = 0; runStatus.failCount = 1; runStatus.failFastEnabled = true; + runStatus.fileCount = 1; + runStatus.observationCount = 1; runStatus.tests = [{ title: 'failed test' }];