Skip to content

Commit bab52ef

Browse files
authored
Merge pull request #63 from kentrino/feat/fast_fail
feat(reporter) add fail fast option
2 parents a71f679 + 795cae1 commit bab52ef

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ karma.conf.js file
3232
...
3333
reporters: ["spec"],
3434
specReporter: {
35-
maxLogLines: 5, // limit number of lines logged per test
36-
suppressErrorSummary: true, // do not print error summary
37-
suppressFailed: false, // do not print information about failed tests
38-
suppressPassed: false, // do not print information about passed tests
39-
suppressSkipped: true, // do not print information about skipped tests
40-
showSpecTiming: false // print the time elapsed for each spec
35+
maxLogLines: 5, // limit number of lines logged per test
36+
suppressErrorSummary: true, // do not print error summary
37+
suppressFailed: false, // do not print information about failed tests
38+
suppressPassed: false, // do not print information about passed tests
39+
suppressSkipped: true, // do not print information about skipped tests
40+
showSpecTiming: false, // print the time elapsed for each spec
41+
failFast: true // test would finish with error when a first fail occurs.
4142
},
4243
plugins: ["karma-spec-reporter"],
4344
...

index.js

+3
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ var SpecReporter = function(baseReporterDecorator, formatError, config) {
137137
this.onSpecFailure = function(browsers, results) {
138138
this.failures.push(results);
139139
this.writeSpecMessage(this.USE_COLORS ? this.prefixes.failure.red : this.prefixes.failure).apply(this, arguments);
140+
if (reporterCfg.failFast) {
141+
throw new Error('Fail fast active for tests, exiting(failFast option is enabled)');
142+
}
140143
};
141144

142145
this.specSuccess = reporterCfg.suppressPassed ? noop : this.writeSpecMessage(this.USE_COLORS ? this.prefixes.success.green : this.prefixes.success);

test/index.spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -349,5 +349,26 @@ describe('SpecReporter', function () {
349349
});
350350
});
351351
});
352+
353+
describe('onSpecFailure', function () {
354+
describe('with FAIL_FAST option', function () {
355+
var newSpecReporter;
356+
var config = {};
357+
beforeEach(function () {
358+
config.specReporter = {
359+
failFast: true
360+
};
361+
newSpecReporter = new SpecReporter[1](baseReporterDecorator, formatError, config);
362+
});
363+
it('should throw an error', function () {
364+
expect(function () {
365+
newSpecReporter.onSpecFailure([],{
366+
suite: [],
367+
log: []
368+
})
369+
}).to.throw(Error, /failFast/);
370+
});
371+
});
372+
});
352373
});
353374
});

0 commit comments

Comments
 (0)