Add the ability to retry flaky tests to Jasmine 1.3 specs

This commit is contained in:
Nathan Sobo 2019-04-10 14:07:51 -06:00
parent 24c0503617
commit 5ac126e01b
1 changed files with 40 additions and 8 deletions

48
vendor/jasmine.js vendored
View File

@ -2021,6 +2021,17 @@ jasmine.Queue = function(env) {
this.abort = false; this.abort = false;
}; };
jasmine.Queue.prototype.clone = function() {
var queue = new jasmine.Queue(this.env);
queue.ensured = this.ensured.slice(0)
queue.blocks = this.blocks.slice(0)
queue.running = this.running;
queue.index = this.index;
queue.offset = this.offset;
queue.abort = this.abort;
return queue;
}
jasmine.Queue.prototype.addBefore = function(block, ensure) { jasmine.Queue.prototype.addBefore = function(block, ensure) {
if (ensure === jasmine.undefined) { if (ensure === jasmine.undefined) {
ensure = false; ensure = false;
@ -2269,7 +2280,11 @@ jasmine.Spec.prototype.addToQueue = function (block) {
* @param {jasmine.ExpectationResult} result * @param {jasmine.ExpectationResult} result
*/ */
jasmine.Spec.prototype.addMatcherResult = function(result) { jasmine.Spec.prototype.addMatcherResult = function(result) {
this.results_.addResult(result); if (this.retries > 0 && !result.passed_) {
this.retry();
} else {
this.results_.addResult(result);
}
}; };
jasmine.Spec.prototype.expect = function(actual) { jasmine.Spec.prototype.expect = function(actual) {
@ -2330,13 +2345,17 @@ jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessag
return this; return this;
}; };
jasmine.Spec.prototype.fail = function (e) { jasmine.Spec.prototype.fail = function (e, onComplete) {
var expectationResult = new jasmine.ExpectationResult({ if (this.retries > 0) {
passed: false, this.retry()
message: e ? jasmine.util.formatException(e) : 'Exception', } else {
trace: { stack: e.stack } var expectationResult = new jasmine.ExpectationResult({
}); passed: false,
this.results_.addResult(expectationResult); message: e ? jasmine.util.formatException(e) : 'Exception',
trace: { stack: e.stack }
});
this.results_.addResult(expectationResult);
}
}; };
jasmine.Spec.prototype.getMatchersClass_ = function() { jasmine.Spec.prototype.getMatchersClass_ = function() {
@ -2454,6 +2473,19 @@ jasmine.Spec.prototype.removeAllSpies = function() {
this.spies_ = []; this.spies_ = [];
}; };
jasmine.Spec.prototype.RETRY_FLAKY_TEST_AND_SLOW_DOWN_THE_BUILD = function() {
if (this.retries == null) {
this.retries = 5;
this.originalQueue = this.queue.clone();
}
}
jasmine.Spec.prototype.retry = function() {
this.retries--;
this.queue = this.originalQueue.clone();
this.suite.queue.insertNext(this)
}
/** /**
* Internal representation of a Jasmine suite. * Internal representation of a Jasmine suite.
* *