Skip to content

Commit

Permalink
Print out warning in verbose & mini reporter when --fail-fast is en…
Browse files Browse the repository at this point in the history
…abled (#1160)
  • Loading branch information
ThomasBem authored and sindresorhus committed Jan 7, 2017
1 parent ab314c4 commit 09d23f5
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ Api.prototype._run = function (files, options) {
var runStatus = new RunStatus({
runOnlyExclusive: options.runOnlyExclusive,
prefixTitles: this.options.explicitTitles || files.length > 1,
base: path.relative('.', commonPathPrefix(files)) + path.sep
base: path.relative('.', commonPathPrefix(files)) + path.sep,
failFast: this.options.failFast
});

this.emit('test-run', runStatus, files);
Expand Down
3 changes: 2 additions & 1 deletion lib/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ module.exports = {
pass: chalk.green,
duration: chalk.gray.dim,
errorStack: chalk.gray,
stack: chalk.red
stack: chalk.red,
failFast: chalk.magenta
};
4 changes: 4 additions & 0 deletions lib/reporters/mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ MiniReporter.prototype.finish = function (runStatus) {
});
}

if (runStatus.failFastEnabled === true) {
status += '\n\n ' + colors.failFast('`--fail-fast` is on. Any number of tests may have been skipped');
}

return status + '\n\n';
};

Expand Down
4 changes: 4 additions & 0 deletions lib/reporters/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ VerboseReporter.prototype.finish = function (runStatus) {
});
}

if (runStatus.failFastEnabled === true) {
output += '\n\n\n ' + colors.failFast('`--fail-fast` is on. Any number of tests may have been skipped');
}

return output + '\n';
};

Expand Down
1 change: 1 addition & 0 deletions lib/run-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class RunStatus extends EventEmitter {
this.errors = [];
this.stats = [];
this.tests = [];
this.failFastEnabled = opts.failFast || false;

autoBind(this);
}
Expand Down
15 changes: 15 additions & 0 deletions test/reporters/mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,21 @@ test('results with unhandled errors', function (t) {
t.end();
});

test('results when fail-fast is enabled', function (t) {
var reporter = miniReporter();
var runStatus = {
failFastEnabled: true
};

var output = reporter.finish(runStatus);
compareLineOutput(t, output, [
'',
'',
' ' + colors.failFast('`--fail-fast` is on. Any number of tests may have been skipped')
]);
t.end();
});

test('results with 1 previous failure', function (t) {
var reporter = miniReporter();
reporter.todoCount = 1;
Expand Down
23 changes: 23 additions & 0 deletions test/reporters/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,29 @@ test('results with errors', function (t) {
t.end();
});

test('results when fail-fast is enabled', function (t) {
var reporter = verboseReporter();
var runStatus = createRunStatus();
runStatus.failCount = 1;
runStatus.failFastEnabled = true;
runStatus.tests = [{
title: 'failed test'
}];

var output = reporter.finish(runStatus);
var expectedOutput = [
'',
' ' + chalk.red('1 test failed') + time,
'',
'',
' ' + colors.failFast('`--fail-fast` is on. Any number of tests may have been skipped'),
''
].join('\n');

t.is(output, expectedOutput);
t.end();
});

test('results with 1 previous failure', function (t) {
var reporter = createReporter();

Expand Down

0 comments on commit 09d23f5

Please sign in to comment.