Remove jasmine internals from stack traces, WIP.
This commit is contained in:
parent
e9a2b0dcdb
commit
5f6fb4f7e1
|
@ -73,7 +73,6 @@ describe('Exceptions:', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var runner = env.currentRunner();
|
|
||||||
suite.execute();
|
suite.execute();
|
||||||
fakeTimer.tick(2500);
|
fakeTimer.tick(2500);
|
||||||
|
|
||||||
|
@ -89,7 +88,7 @@ describe('Exceptions:', function() {
|
||||||
expect(blockResults[0].message).toMatch(/fake error 1/);
|
expect(blockResults[0].message).toMatch(/fake error 1/);
|
||||||
|
|
||||||
expect(specResults[1].passed()).toEqual(false);
|
expect(specResults[1].passed()).toEqual(false);
|
||||||
var blockResults = specResults[1].getItems();
|
blockResults = specResults[1].getItems();
|
||||||
expect(blockResults[0].passed()).toEqual(false);
|
expect(blockResults[0].passed()).toEqual(false);
|
||||||
expect(blockResults[0].message).toMatch(/fake error 2/),
|
expect(blockResults[0].message).toMatch(/fake error 2/),
|
||||||
expect(blockResults[1].passed()).toEqual(true);
|
expect(blockResults[1].passed()).toEqual(true);
|
||||||
|
@ -101,7 +100,44 @@ describe('Exceptions:', function() {
|
||||||
expect(blockResults[0].message).toMatch(/fake error 3/);
|
expect(blockResults[0].message).toMatch(/fake error 3/);
|
||||||
|
|
||||||
expect(specResults[4].passed()).toEqual(true);
|
expect(specResults[4].passed()).toEqual(true);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should remove jasmine internals from reported stack traces", function() {
|
||||||
|
var spec;
|
||||||
|
var suite = env.describe('Suite for handles exceptions', function () {
|
||||||
|
spec = env.it('should be a test that fails because it throws an exception', function() {
|
||||||
|
function someNamedFunction() {
|
||||||
|
this.expect(true).toEqual(false);
|
||||||
|
throw new Error('fake error 1');
|
||||||
|
}
|
||||||
|
someNamedFunction.call(this);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
suite.execute();
|
||||||
|
|
||||||
|
var webKitRegex = /^ at .*?(new |\.)([^. ]*) \((.+:[0-9]+:[0-9]+)\)+$/;
|
||||||
|
var firefoxRegex = /^([^.(]*)\(.*\)@(.+:[0-9]+)$/;
|
||||||
|
|
||||||
|
var stackLinks = spec.results().getItems()[0].stackTrace().split("\n");
|
||||||
|
var stackInfos = [];
|
||||||
|
for (var i = 0; i < stackLinks.length; i++) {
|
||||||
|
|
||||||
|
var match;
|
||||||
|
if (match = webKitRegex.exec(stackLinks[i])) {
|
||||||
|
stackInfos.push(match[2] + ": " + stackLinks[i]);
|
||||||
|
} else if (match = firefoxRegex.exec(stackLinks[i])) {
|
||||||
|
stackInfos.push(match[1]);
|
||||||
|
} else {
|
||||||
|
stackInfos.push(stackLinks[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect(stackInfos).toEqual([
|
||||||
|
"Error: Expected true to equal false.",
|
||||||
|
"__jasmine_Matchers_matcherFn__",
|
||||||
|
"someNamedFunction",
|
||||||
|
"<anonymous>"
|
||||||
|
]);
|
||||||
|
expect({a:1,b:2,c:3}).toEqual({d:4,e:5,f:6});
|
||||||
|
});
|
||||||
});
|
});
|
|
@ -12,7 +12,7 @@ jasmine.Block = function(env, func, spec) {
|
||||||
this.spec = spec;
|
this.spec = spec;
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.Block.prototype.execute = function(onComplete) {
|
jasmine.Block.prototype.execute = function __jasmine_Block_prototype_execute__(onComplete) {
|
||||||
try {
|
try {
|
||||||
this.func.apply(this.spec);
|
this.func.apply(this.spec);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -45,7 +45,7 @@ jasmine.Matchers.wrapInto_ = function(prototype, matchersClass) {
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
|
jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
|
||||||
return function() {
|
var wrapper = function __jasmine_Matchers_matcherFn__() {
|
||||||
var matcherArgs = jasmine.util.argsToArray(arguments);
|
var matcherArgs = jasmine.util.argsToArray(arguments);
|
||||||
var result = matcherFunction.apply(this, arguments);
|
var result = matcherFunction.apply(this, arguments);
|
||||||
|
|
||||||
|
@ -84,11 +84,12 @@ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
|
||||||
this.spec.addMatcherResult(expectationResult);
|
this.spec.addMatcherResult(expectationResult);
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
var fn = eval("(function __jasmine_Matchers_$" + matcherName + "$_Matcher__(matcherFn, args) { return matcherFn.apply(this, args); });");
|
||||||
|
return function() { return fn.call(this, wrapper, arguments)};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* toBe: compares the actual to the expected using ===
|
* toBe: compares the actual to the expected using ===
|
||||||
* @param expected
|
* @param expected
|
||||||
|
|
27
src/base.js
27
src/base.js
|
@ -57,7 +57,8 @@ jasmine.MessageResult = function(text) {
|
||||||
this.trace = new Error(); // todo: test better
|
this.trace = new Error(); // todo: test better
|
||||||
};
|
};
|
||||||
|
|
||||||
jasmine.ExpectationResult = function(params) {
|
(function() {
|
||||||
|
jasmine.ExpectationResult = function __jasmine_ExpectationResult__(params) {
|
||||||
this.type = 'ExpectationResult';
|
this.type = 'ExpectationResult';
|
||||||
this.matcherName = params.matcherName;
|
this.matcherName = params.matcherName;
|
||||||
this.passed_ = params.passed;
|
this.passed_ = params.passed;
|
||||||
|
@ -69,12 +70,34 @@ jasmine.ExpectationResult = function(params) {
|
||||||
|
|
||||||
this.message = this.passed_ ? 'Passed.' : params.message;
|
this.message = this.passed_ ? 'Passed.' : params.message;
|
||||||
this.trace = this.passed_ ? '' : new Error(this.message);
|
this.trace = this.passed_ ? '' : new Error(this.message);
|
||||||
};
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
jasmine.ExpectationResult.prototype.passed = function () {
|
jasmine.ExpectationResult.prototype.passed = function () {
|
||||||
return this.passed_;
|
return this.passed_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
jasmine.ExpectationResult.prototype.stackTrace = function () {
|
||||||
|
var trace = [];
|
||||||
|
var orig = this.trace.stack.split("\n");
|
||||||
|
var skipNext = false;
|
||||||
|
for (var i = 0; i < orig.length; i++) {
|
||||||
|
if (skipNext) { skipNext = false; continue; }
|
||||||
|
if (orig[i].match(/__jasmine_Matchers_matcherFn__/)) continue;
|
||||||
|
if (orig[i].match(/__jasmine_ExpectationResult__/)) continue;
|
||||||
|
var match;
|
||||||
|
if (match = orig[i].match(/__jasmine_Matchers_\$([^ .()]+)\$_Matcher__/)) {
|
||||||
|
trace.push(orig[i]);
|
||||||
|
trace.push(match[1]);
|
||||||
|
skipNext = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (orig[i].match(/__jasmine_Block_prototype_execute__/)) break;
|
||||||
|
trace.push(orig[i]);
|
||||||
|
}
|
||||||
|
return trace.join("\n");
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter for the Jasmine environment. Ensures one gets created
|
* Getter for the Jasmine environment. Ensures one gets created
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue