Reintroduce fn that clears stack occasionally
- setTimeout will clear stack, prevent overflow. We run this once every thousand specs. - Browser users will probably want a time-based clear rather than spec count based clear, as a thousand tests is typically quite slow. The reporter should provide this.
This commit is contained in:
@@ -524,6 +524,8 @@ jasmine.buildExpectationResult = function(params) {
|
||||
var self = this;
|
||||
var global = options.global || jasmine.getGlobal();
|
||||
|
||||
var encourageGC = options.encourageGarbageCollection || encourageGarbageCollection;
|
||||
|
||||
this.clock = new jasmine.Clock(global, new jasmine.DelayedFunctionScheduler());
|
||||
|
||||
var suiteConstructor = jasmine.Suite;
|
||||
@@ -539,8 +541,6 @@ jasmine.buildExpectationResult = function(params) {
|
||||
|
||||
this.reporter = new jasmine.MultiReporter();
|
||||
|
||||
this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL;
|
||||
this.defaultTimeoutInterval = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||
this.lastUpdate = 0;
|
||||
this.specFilter = function() {
|
||||
return true;
|
||||
@@ -627,8 +627,11 @@ jasmine.buildExpectationResult = function(params) {
|
||||
function specResultCallback(result) {
|
||||
self.clock.uninstall();
|
||||
self.currentSpec = null;
|
||||
suite.specComplete(result);
|
||||
encourageGC(function() {
|
||||
suite.specComplete(result);
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var queueConstructor = jasmine.Queue;
|
||||
@@ -639,6 +642,18 @@ jasmine.buildExpectationResult = function(params) {
|
||||
return new suiteConstructor(self, description, specDefinitions, self.currentSuite, queueFactory, isSuite);
|
||||
};
|
||||
|
||||
var maximumSpecCallbackDepth = 100;
|
||||
var currentSpecCallbackDepth = 0;
|
||||
function encourageGarbageCollection(fn) {
|
||||
currentSpecCallbackDepth++;
|
||||
if (currentSpecCallbackDepth > maximumSpecCallbackDepth) {
|
||||
currentSpecCallbackDepth = 0;
|
||||
global.setTimeout(fn, 0);
|
||||
} else {
|
||||
fn();
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
//TODO: shim Spec addMatchers behavior into Env. Should be rewritten to remove globals, etc.
|
||||
|
||||
@@ -159,6 +159,7 @@ process.argv.forEach(function(arg) {
|
||||
}
|
||||
});
|
||||
|
||||
// var specs = jasmine.getAllSpecFiles(__dirname + '/smoke', new RegExp("test.js$"));
|
||||
var specs = jasmine.getAllSpecFiles(__dirname, new RegExp("Spec.js$"));
|
||||
var domIndependentSpecs = [];
|
||||
for (var i = 0; i < specs.length; i++) {
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
var self = this;
|
||||
var global = options.global || jasmine.getGlobal();
|
||||
|
||||
var encourageGC = options.encourageGarbageCollection || encourageGarbageCollection;
|
||||
|
||||
this.clock = new jasmine.Clock(global, new jasmine.DelayedFunctionScheduler());
|
||||
|
||||
var suiteConstructor = jasmine.Suite;
|
||||
@@ -24,8 +26,6 @@
|
||||
|
||||
this.reporter = new jasmine.MultiReporter();
|
||||
|
||||
this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL;
|
||||
this.defaultTimeoutInterval = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||
this.lastUpdate = 0;
|
||||
this.specFilter = function() {
|
||||
return true;
|
||||
@@ -112,8 +112,11 @@
|
||||
function specResultCallback(result) {
|
||||
self.clock.uninstall();
|
||||
self.currentSpec = null;
|
||||
suite.specComplete(result);
|
||||
encourageGC(function() {
|
||||
suite.specComplete(result);
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
var queueConstructor = jasmine.Queue;
|
||||
@@ -124,6 +127,18 @@
|
||||
return new suiteConstructor(self, description, specDefinitions, self.currentSuite, queueFactory, isSuite);
|
||||
};
|
||||
|
||||
var maximumSpecCallbackDepth = 100;
|
||||
var currentSpecCallbackDepth = 0;
|
||||
function encourageGarbageCollection(fn) {
|
||||
currentSpecCallbackDepth++;
|
||||
if (currentSpecCallbackDepth > maximumSpecCallbackDepth) {
|
||||
currentSpecCallbackDepth = 0;
|
||||
global.setTimeout(fn, 0);
|
||||
} else {
|
||||
fn();
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
//TODO: shim Spec addMatchers behavior into Env. Should be rewritten to remove globals, etc.
|
||||
|
||||
Reference in New Issue
Block a user