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:
Davis W. Frank & Rajan Agaskar
2012-12-07 12:26:05 -08:00
parent c584f182ab
commit 234f2a1585
3 changed files with 37 additions and 6 deletions

View File

@@ -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.

View File

@@ -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++) {

View File

@@ -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.