Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 02defe3

Browse files
committed
refactor(jasminewd): full stacktraces fixups
Include full stacktraces when expecing a promise to equal a promise. Include the original stack trace for errors caught by the control flow. Sometimes the original stack trace contains important line item information. Increase the list of files that are filtered out of stack traces.
1 parent 767c306 commit 02defe3

File tree

3 files changed

+59
-19
lines changed

3 files changed

+59
-19
lines changed

debugging/failure_spec.js

+25
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,36 @@ describe('modes of failure', function() {
2424
browser.get('http://www.google.com');
2525
}, 20000);
2626

27+
it('should fail within a promise', function () {
28+
browser.get('index.html#/form');
29+
var greeting = element(by.binding('{{greeting}}'));
30+
31+
greeting.getText().then(function(text) {
32+
expect(text).toEqual('This is not what it equals');
33+
});
34+
});
35+
2736
it('should fail an assertion', function() {
2837
browser.get('index.html#/form');
2938

3039
var greeting = element(by.binding('{{greeting}}'));
3140

3241
expect(greeting.getText()).toEqual('This is not what it equals');
3342
});
43+
44+
it('should fail comparing a promise to another promise', function() {
45+
browser.get('index.html#/form');
46+
47+
var greeting = element(by.binding('{{greeting}}'));
48+
49+
expect(greeting.getText()).toEqual(greeting.getAttribute('value'));
50+
});
51+
52+
53+
it('should fail because it throws an error', function() {
54+
function foo() {
55+
throw new Error('bar!');
56+
}
57+
foo();
58+
});
3459
});

jasminewd/index.js

+17-14
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function wrapInControlFlow(globalFn) {
3535
var thing = flow.execute(function() {
3636
fn.call(jasmine.getEnv().currentSpec);
3737
}).then(seal(done), function(e) {
38-
e.stack = driverError.stack;
38+
e.stack = driverError.stack + '\nAt async task:\n ' + e.stack;
3939
done(e);
4040
});
4141
};
@@ -82,31 +82,34 @@ function wrapMatcher(matcher, actualPromise, not) {
8282
matchError.stack = matchError.stack.replace(/ +at.+jasminewd.+\n/, '');
8383
actualPromise.then(function(actual) {
8484
var expected = originalArgs[0];
85+
86+
var expectation = expect(actual);
87+
if (not) {
88+
expectation = expectation.not;
89+
}
90+
var originalAddMatcherResult = expectation.spec.addMatcherResult;
91+
var error = matchError;
92+
expectation.spec.addMatcherResult = function(result) {
93+
result.trace = error;
94+
jasmine.Spec.prototype.addMatcherResult.call(this, result);
95+
};
96+
8597
if (expected instanceof webdriver.promise.Promise) {
8698
if (originalArgs.length > 1) {
8799
throw error('Multi-argument matchers with promises are not '
88100
+ 'supported.');
89101
}
90102
expected.then(function(exp) {
91-
if (not) {
92-
expect(actual).not[matcher](exp)
93-
} else {
94-
expect(actual)[matcher](exp);
95-
}
103+
expectation[matcher].apply(expectation, [exp]);
104+
expectation.spec.addMatcherResult = originalAddMatcherResult;
96105
});
97106
} else {
98-
var expectation = expect(actual);
99-
if (not) {
100-
expectation = expectation.not;
101-
}
102-
var origFn = expectation.spec.addMatcherResult;
103-
var error = matchError;
104107
expectation.spec.addMatcherResult = function(result) {
105108
result.trace = error;
106-
jasmine.Spec.prototype.addMatcherResult.call(this, result);
109+
originalAddMatcherResult.call(this, result);
107110
}
108111
expectation[matcher].apply(expectation, originalArgs);
109-
expectation.spec.addMatcherResult = origFn;
112+
expectation.spec.addMatcherResult = originalAddMatcherResult;
110113
}
111114
});
112115
};

lib/protractor.js

+17-5
Original file line numberDiff line numberDiff line change
@@ -829,12 +829,24 @@ exports.filterStackTrace = function(text) {
829829
if (!text) {
830830
return text;
831831
}
832-
var jasmineFilename = 'node_modules/minijasminenode/lib/jasmine-1.3.1.js';
833-
var seleniumFilename = 'node_modules/selenium-webdriver';
832+
var substringsToFilter = [
833+
'node_modules/minijasminenode/lib/',
834+
'node_modules/selenium-webdriver',
835+
'at Module.',
836+
'at Object.Module.',
837+
'at Function.Module',
838+
'(timers.js:',
839+
'jasminewd/index.js'
840+
];
834841
var lines = [];
835-
text.split(/\n/).forEach(function(line){
836-
if (line.indexOf(jasmineFilename) == -1 &&
837-
line.indexOf(seleniumFilename) == -1) {
842+
text.split(/\n/).forEach(function(line) {
843+
var include = true;
844+
for (var i = 0; i < substringsToFilter.length; ++i) {
845+
if (line.indexOf(substringsToFilter[i]) !== -1) {
846+
include = false;
847+
}
848+
}
849+
if (include) {
838850
lines.push(line);
839851
}
840852
});

0 commit comments

Comments
 (0)