Skip to content

Commit

Permalink
Print out warning in verbose and mini reporter when --fail-fast is en…
Browse files Browse the repository at this point in the history
…abled
  • Loading branch information
Thomas committed Dec 21, 2016
1 parent 033d4dc commit dae7fa7
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 2 deletions.
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 @@ -220,6 +220,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
11 changes: 11 additions & 0 deletions lib/run-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ function normalizeError(err) {
return err;
}

function isFailFastEnabled(stat) {
if (stat.failFastEnabled === true) {
return stat;
}
}

class RunStatus extends EventEmitter {
constructor(opts) {
super();
Expand All @@ -50,6 +56,7 @@ class RunStatus extends EventEmitter {
this.errors = [];
this.stats = [];
this.tests = [];
this.failFastEnabled = false;

autoBind(this);
}
Expand Down Expand Up @@ -138,6 +145,10 @@ class RunStatus extends EventEmitter {
this.skipCount = sum(this.stats, 'skipCount');
this.todoCount = sum(this.stats, 'todoCount');
this.failCount = sum(this.stats, 'failCount');
var failFastIsEnabled = this.stats.find(isFailFastEnabled);
if (failFastIsEnabled !== undefined && failFastIsEnabled.failFastEnabled === true) {
this.failFastEnabled = true;
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,14 @@ class Runner extends EventEmitter {
const stats = {
testCount: 0,
skipCount: 0,
todoCount: 0
todoCount: 0,
failFastEnabled: false
};

if (this._bail === true) {
stats.failFastEnabled = true;
}

this.results
.map(result => {
return result.result;
Expand Down
15 changes: 15 additions & 0 deletions test/reporters/mini.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,21 @@ test('results with 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
16 changes: 16 additions & 0 deletions test/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,19 @@ test('match applies to arrays of macros', t => {
t.end();
});
});

test('stats.failFastEnabled is false when bail is not set', t => {
const runner = new Runner();
var stats = runner._buildStats();

t.is(stats.failFastEnabled, false);
t.end();
});

test('stats.failFastEnabled is true when bail is set', t => {
const runner = new Runner({bail: true});
var stats = runner._buildStats();

t.is(stats.failFastEnabled, true);
t.end();
});

0 comments on commit dae7fa7

Please sign in to comment.