Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove jasmine internals from stack traces, WIP.

  • Loading branch information...
commit 5f6fb4f7e1271584cef49237622fb9db8aac7a8d 1 parent e9a2b0d
@xian xian authored
View
42 spec/suites/ExceptionsSpec.js
@@ -73,7 +73,6 @@ describe('Exceptions:', function() {
});
});
- var runner = env.currentRunner();
suite.execute();
fakeTimer.tick(2500);
@@ -89,7 +88,7 @@ describe('Exceptions:', function() {
expect(blockResults[0].message).toMatch(/fake error 1/);
expect(specResults[1].passed()).toEqual(false);
- var blockResults = specResults[1].getItems();
+ blockResults = specResults[1].getItems();
expect(blockResults[0].passed()).toEqual(false);
expect(blockResults[0].message).toMatch(/fake error 2/),
expect(blockResults[1].passed()).toEqual(true);
@@ -101,7 +100,44 @@ describe('Exceptions:', function() {
expect(blockResults[0].message).toMatch(/fake error 3/);
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});
+ });
});
View
2  src/Block.js
@@ -12,7 +12,7 @@ jasmine.Block = function(env, func, spec) {
this.spec = spec;
};
-jasmine.Block.prototype.execute = function(onComplete) {
+jasmine.Block.prototype.execute = function __jasmine_Block_prototype_execute__(onComplete) {
try {
this.func.apply(this.spec);
} catch (e) {
View
5 src/Matchers.js
@@ -45,7 +45,7 @@ jasmine.Matchers.wrapInto_ = function(prototype, matchersClass) {
};
jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
- return function() {
+ var wrapper = function __jasmine_Matchers_matcherFn__() {
var matcherArgs = jasmine.util.argsToArray(arguments);
var result = matcherFunction.apply(this, arguments);
@@ -84,11 +84,12 @@ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) {
this.spec.addMatcherResult(expectationResult);
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 ===
* @param expected
View
49 src/base.js
@@ -57,24 +57,47 @@ jasmine.MessageResult = function(text) {
this.trace = new Error(); // todo: test better
};
-jasmine.ExpectationResult = function(params) {
- this.type = 'ExpectationResult';
- this.matcherName = params.matcherName;
- this.passed_ = params.passed;
- this.expected = params.expected;
- this.actual = params.actual;
-
- /** @deprecated */
- this.details = params.details;
-
- this.message = this.passed_ ? 'Passed.' : params.message;
- this.trace = this.passed_ ? '' : new Error(this.message);
-};
+(function() {
+ jasmine.ExpectationResult = function __jasmine_ExpectationResult__(params) {
+ this.type = 'ExpectationResult';
+ this.matcherName = params.matcherName;
+ this.passed_ = params.passed;
+ this.expected = params.expected;
+ this.actual = params.actual;
+
+ /** @deprecated */
+ this.details = params.details;
+
+ this.message = this.passed_ ? 'Passed.' : params.message;
+ this.trace = this.passed_ ? '' : new Error(this.message);
+ };
+})();
jasmine.ExpectationResult.prototype.passed = function () {
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
*/
Please sign in to comment.
Something went wrong with that request. Please try again.