Allow tests to run in random order

This commit is contained in:
Marcio Junior
2015-09-26 11:25:33 -03:00
parent 375a6f9fda
commit 3f3fa484b2
12 changed files with 423 additions and 10 deletions

View File

@@ -20,6 +20,8 @@ getJasmineRequireObj().Env = function(j$) {
var currentlyExecutingSuites = [];
var currentDeclarationSuite = null;
var throwOnExpectationFailure = false;
var random = false;
var seed = null;
var currentSuite = function() {
return currentlyExecutingSuites[currentlyExecutingSuites.length - 1];
@@ -169,6 +171,21 @@ getJasmineRequireObj().Env = function(j$) {
return throwOnExpectationFailure;
};
this.randomizeTests = function(value) {
random = !!value;
};
this.randomTests = function() {
return random;
};
this.seed = function(value) {
if (value) {
seed = value;
}
return seed;
};
var queueRunnerFactory = function(options) {
options.catchException = catchException;
options.clearStack = options.clearStack || clearStack;
@@ -200,6 +217,12 @@ getJasmineRequireObj().Env = function(j$) {
runnablesToRun = [topSuite.id];
}
}
var order = new j$.Order({
random: random,
seed: seed
});
var processor = new j$.TreeProcessor({
tree: topSuite,
runnableIds: runnablesToRun,
@@ -215,6 +238,9 @@ getJasmineRequireObj().Env = function(j$) {
}
currentlyExecutingSuites.pop();
reporter.suiteDone(result);
},
orderChildren: function(node) {
return order.sort(node.children);
}
});
@@ -226,7 +252,11 @@ getJasmineRequireObj().Env = function(j$) {
totalSpecsDefined: totalSpecsDefined
});
processor.execute(reporter.jasmineDone);
processor.execute(function() {
reporter.jasmineDone({
order: order
});
});
};
this.addReporter = function(reporterToAdd) {