Skip to content

Commit dae7fa7

Browse files
author
Thomas
committed
Print out warning in verbose and mini reporter when --fail-fast is enabled
1 parent 033d4dc commit dae7fa7

File tree

8 files changed

+81
-2
lines changed

8 files changed

+81
-2
lines changed

lib/colors.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ module.exports = {
99
pass: chalk.green,
1010
duration: chalk.gray.dim,
1111
errorStack: chalk.gray,
12-
stack: chalk.red
12+
stack: chalk.red,
13+
failFast: chalk.magenta
1314
};

lib/reporters/mini.js

+4
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ MiniReporter.prototype.finish = function (runStatus) {
220220
});
221221
}
222222

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

lib/reporters/verbose.js

+4
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ VerboseReporter.prototype.finish = function (runStatus) {
114114
});
115115
}
116116

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

lib/run-status.js

+11
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ function normalizeError(err) {
2828
return err;
2929
}
3030

31+
function isFailFastEnabled(stat) {
32+
if (stat.failFastEnabled === true) {
33+
return stat;
34+
}
35+
}
36+
3137
class RunStatus extends EventEmitter {
3238
constructor(opts) {
3339
super();
@@ -50,6 +56,7 @@ class RunStatus extends EventEmitter {
5056
this.errors = [];
5157
this.stats = [];
5258
this.tests = [];
59+
this.failFastEnabled = false;
5360

5461
autoBind(this);
5562
}
@@ -138,6 +145,10 @@ class RunStatus extends EventEmitter {
138145
this.skipCount = sum(this.stats, 'skipCount');
139146
this.todoCount = sum(this.stats, 'todoCount');
140147
this.failCount = sum(this.stats, 'failCount');
148+
var failFastIsEnabled = this.stats.find(isFailFastEnabled);
149+
if (failFastIsEnabled !== undefined && failFastIsEnabled.failFastEnabled === true) {
150+
this.failFastEnabled = true;
151+
}
141152
}
142153
}
143154

lib/runner.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,14 @@ class Runner extends EventEmitter {
107107
const stats = {
108108
testCount: 0,
109109
skipCount: 0,
110-
todoCount: 0
110+
todoCount: 0,
111+
failFastEnabled: false
111112
};
112113

114+
if (this._bail === true) {
115+
stats.failFastEnabled = true;
116+
}
117+
113118
this.results
114119
.map(result => {
115120
return result.result;

test/reporters/mini.js

+15
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,21 @@ test('results with errors', function (t) {
383383
t.end();
384384
});
385385

386+
test('results when fail-fast is enabled', function (t) {
387+
var reporter = miniReporter();
388+
var runStatus = {
389+
failFastEnabled: true
390+
};
391+
392+
var output = reporter.finish(runStatus);
393+
compareLineOutput(t, output, [
394+
'',
395+
'',
396+
' ' + colors.failFast('`--fail-fast` is on. Any number of tests may have been skipped')
397+
]);
398+
t.end();
399+
});
400+
386401
test('results with 1 previous failure', function (t) {
387402
var reporter = miniReporter();
388403
reporter.todoCount = 1;

test/reporters/verbose.js

+23
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,29 @@ test('results with errors', function (t) {
381381
t.end();
382382
});
383383

384+
test('results when fail-fast is enabled', function (t) {
385+
var reporter = verboseReporter();
386+
var runStatus = createRunStatus();
387+
runStatus.failCount = 1;
388+
runStatus.failFastEnabled = true;
389+
runStatus.tests = [{
390+
title: 'failed test'
391+
}];
392+
393+
var output = reporter.finish(runStatus);
394+
var expectedOutput = [
395+
'',
396+
' ' + chalk.red('1 test failed') + time,
397+
'',
398+
'',
399+
' ' + colors.failFast('`--fail-fast` is on. Any number of tests may have been skipped'),
400+
''
401+
].join('\n');
402+
403+
t.is(output, expectedOutput);
404+
t.end();
405+
});
406+
384407
test('results with 1 previous failure', function (t) {
385408
var reporter = createReporter();
386409

test/runner.js

+16
Original file line numberDiff line numberDiff line change
@@ -659,3 +659,19 @@ test('match applies to arrays of macros', t => {
659659
t.end();
660660
});
661661
});
662+
663+
test('stats.failFastEnabled is false when bail is not set', t => {
664+
const runner = new Runner();
665+
var stats = runner._buildStats();
666+
667+
t.is(stats.failFastEnabled, false);
668+
t.end();
669+
});
670+
671+
test('stats.failFastEnabled is true when bail is set', t => {
672+
const runner = new Runner({bail: true});
673+
var stats = runner._buildStats();
674+
675+
t.is(stats.failFastEnabled, true);
676+
t.end();
677+
});

0 commit comments

Comments
 (0)