Skip to content

Commit

Permalink
Add failFast support
Browse files Browse the repository at this point in the history
- Add a new config option `failFast`. Setting this to a truthy value
  will cause all subsequent tests after a failing test to be skipped.
- Support a new `skipped` property on suites. This property behaves
  similarly to `Test#skipped`. Setting it to a non-null value will cause
  the remainder of a suite (all tests and nested suites) to be skipped.

References theintern#413
  • Loading branch information
jason0x43 committed Jan 6, 2016
1 parent 76bb410 commit f76eb1c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
2 changes: 2 additions & 0 deletions lib/ClientSuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ define([

case 'suiteEnd':
suite = arguments[1];
self.skipped = suite.skipped;

// The suite sent by the server is the root suite for the client-side unit tests; update the
// existing test objects with the new ones from the server that reflect all the test results
if (!suite.hasParent) {
Expand Down
44 changes: 38 additions & 6 deletions lib/Suite.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
define([
'dojo/Promise',
'dojo/lang'
], function (Promise, lang) {
'dojo/Promise'
], function (Promise) {
function Suite(kwArgs) {
this.tests = [];
for (var k in kwArgs) {
Expand All @@ -11,6 +10,8 @@ define([
this.reporterManager && this.reporterManager.emit('newSuite', this);
}

var failFastReason = 'fail fast';

Suite.prototype = {
constructor: Suite,
name: null,
Expand All @@ -22,6 +23,7 @@ define([
teardown: null,
error: null,
timeElapsed: null,
_failFast: null,
_grep: null,
_remote: null,
_environmentType: null,
Expand All @@ -33,6 +35,17 @@ define([
*/
publishAfterSetup: false,

/**
* A flag used to indicate whether a test run shoudl stop after a failed test.
*/
get failFast() {
return this._failFast || (this.parent && this.parent.failFast);
},

set failFast(value) {
this._failFast = value;
},

/**
* A regular expression used to filter, by test ID, which tests are run.
*/
Expand Down Expand Up @@ -291,8 +304,8 @@ define([
throw reason;
});

function next() {
var test = tests[i++];
function next(test) {
test = test || tests[i++];

if (!test) {
firstError ? reject(firstError) : resolve();
Expand All @@ -318,12 +331,23 @@ define([
}
}

// If the suite will be skipped, mark the current test as skipped. This will skip both
// individual tests and nested suites.
if (self.skipped) {
test.skipped = self.skipped;
}

// test is a suite
if (test.tests) {
current = runWithCatch();
}
// test is a single test
else {
if (!self.grep.test(test.id)) {
test.skipped = 'grep';
}

if (test.skipped) {
reporterManager.emit('testSkip', test).then(next);
return;
}
Expand All @@ -339,7 +363,14 @@ define([
});
}

current.then(next);
current.then(function () {
// If the test was a suite and the suite was skipped due to failFast, mark this suite as
// skipped.
if (test.tests && test.skipped === failFastReason) {
self.skipped = self.skipped || test.skipped;
}
next();
});
}

next();
Expand Down Expand Up @@ -404,6 +435,7 @@ define([
numTests: this.numTests,
numFailedTests: this.numFailedTests,
numSkippedTests: this.numSkippedTests,
skipped: this.skipped,
error: this.error ? {
name: this.error.name,
message: this.error.message,
Expand Down
3 changes: 2 additions & 1 deletion lib/executors/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ define([
grep: config.grep,
sessionId: config.sessionId,
timeout: config.defaultTimeout,
reporterManager: this.reporterManager
reporterManager: this.reporterManager,
failFast: config.failFast
});

this.suites = [ suite ];
Expand Down
1 change: 1 addition & 0 deletions lib/executors/Runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ define([
reporterManager: reporterManager,
publishAfterSetup: true,
grep: config.grep,
failFast: config.failFast,
timeout: config.defaultTimeout,
setup: function () {
return util.retry(function () {
Expand Down

0 comments on commit f76eb1c

Please sign in to comment.