Skip to content

Commit

Permalink
Only print fail-fast when there are remaning tests (#1179)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarlehansen authored and sindresorhus committed Jan 19, 2017
1 parent a2d7973 commit 5a3b792
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/reporters/mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ MiniReporter.prototype.finish = function (runStatus) {
});
}

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

Expand Down
2 changes: 1 addition & 1 deletion lib/reporters/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ VerboseReporter.prototype.finish = function (runStatus) {
});
}

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

Expand Down
28 changes: 28 additions & 0 deletions test/reporters/mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ test('results with unhandled errors', function (t) {
test('results when fail-fast is enabled', function (t) {
var reporter = miniReporter();
var runStatus = {
remainingCount: 1,
failCount: 1,
failFastEnabled: true
};

Expand All @@ -429,6 +431,32 @@ test('results when fail-fast is enabled', function (t) {
t.end();
});

test('results without fail-fast if no failing tests', function (t) {
var reporter = miniReporter();
var runStatus = {
remainingCount: 1,
failCount: 0,
failFastEnabled: true
};

var output = reporter.finish(runStatus);
t.is(output, '\n\n');
t.end();
});

test('results without fail-fast if no skipped tests', function (t) {
var reporter = miniReporter();
var runStatus = {
remainingCount: 0,
failCount: 1,
failFastEnabled: true
};

var output = reporter.finish(runStatus);
t.is(output, '\n\n');
t.end();
});

test('results with 1 previous failure', function (t) {
var reporter = miniReporter();
reporter.todoCount = 1;
Expand Down
41 changes: 41 additions & 0 deletions test/reporters/verbose.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ test('results with errors', function (t) {
test('results when fail-fast is enabled', function (t) {
var reporter = verboseReporter();
var runStatus = createRunStatus();
runStatus.remainingCount = 1;
runStatus.failCount = 1;
runStatus.failFastEnabled = true;
runStatus.tests = [{
Expand All @@ -404,6 +405,46 @@ test('results when fail-fast is enabled', function (t) {
t.end();
});

test('results without fail-fast if no failing tests', function (t) {
var reporter = verboseReporter();
var runStatus = createRunStatus();
runStatus.remainingCount = 1;
runStatus.failCount = 0;
runStatus.passCount = 1;
runStatus.failFastEnabled = true;

var output = reporter.finish(runStatus);
var expectedOutput = [
'',
' ' + chalk.green('1 test passed') + time,
''
].join('\n');

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

test('results without fail-fast if no skipped tests', function (t) {
var reporter = verboseReporter();
var runStatus = createRunStatus();
runStatus.remainingCount = 0;
runStatus.failCount = 1;
runStatus.failFastEnabled = true;
runStatus.tests = [{
title: 'failed test'
}];

var output = reporter.finish(runStatus);
var expectedOutput = [
'',
' ' + chalk.red('1 test failed') + time,
''
].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 5a3b792

Please sign in to comment.