Skip to content

Commit

Permalink
Print number of skipped test files when --fail-fast is used
Browse files Browse the repository at this point in the history
  • Loading branch information
novemberborn committed Feb 11, 2018
1 parent b501fa2 commit 8de2630
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 11 deletions.
1 change: 1 addition & 0 deletions api.js
Expand Up @@ -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
});

Expand Down
19 changes: 16 additions & 3 deletions lib/reporters/mini.js
Expand Up @@ -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) {
Expand Down
19 changes: 16 additions & 3 deletions lib/reporters/verbose.js
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion lib/run-status.js
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
73 changes: 69 additions & 4 deletions test/reporters/mini.js
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
80 changes: 80 additions & 0 deletions test/reporters/verbose.js
Expand Up @@ -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'
}];
Expand All @@ -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'
}];
Expand All @@ -632,13 +636,87 @@ 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();
runStatus.remainingCount = 1;
runStatus.failCount = 0;
runStatus.passCount = 1;
runStatus.failFastEnabled = true;
runStatus.fileCount = 1;
runStatus.observationCount = 1;

const output = reporter.finish(runStatus);
const expectedOutput = [
Expand All @@ -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'
}];
Expand Down

0 comments on commit 8de2630

Please sign in to comment.