AnalyticalGraphicsInc/cesium — pull request #702 by nobelium (2013-04-26 17:34:28+00:00)
Title: Fix for #659

The problem here is that the function wrapWithDebugger() is being called twice by jasmine.HtmlReporter.specFilter() (or self.specFilter) (in jasmine-html.js) , i.e each file is debugged twice. It can be fixed by planting a flag for each file and if it was already debugged the debugging step can be skipped.

var state = {};
function wrapWithDebugger(originalFunction) {
return function() {
var stepIntoThisFunction = originalFunction.bind(this);
debugger;
stepIntoThisFunction();
};
}

var state = {};

self.specFilter = function(spec) {
var paramMap = [];
var params = jasmine.HtmlReporter.parameters(doc);

for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
}

if (paramMap.debug && spec.getFullName() === paramMap.debug && state[spec.id]==undefined) {
var block = spec.queue.blocks[0];
block.func = wrapWithDebugger(block.func);
}

state[spec.id]=true;

But this is not a proper fix, so I looked at the specFilter function and eventually found out that it was also being called twice. I looked at the function that called the specFilter function ie. jasmine.HtmlReporter.addSpecs() but it was being called only once, so the actual problem begins from now. I searched a lot and finally found

env.addReporter(reporter);
env.specFilter = reporter.specFilter;
env.execute();

this in SpecRunner.js where env is an instance of jasmine.getEnv() and reporter is an instance of jasmine.HtmlReporter(); env gets the specFilter definition from reporter and executes it in env.execute(); When a proper method called addSpecs is available to execute specFilter why it separately added to env and executed again?? If I'm wrong do let me know.. By the way, I have commented env.specFilter = reporter.specFilter and ran jsHint and all the test, they passed successfully...