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

Commit

Permalink
refactor(jasminewd): full stacktraces fixups
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
juliemr committed Feb 28, 2014
1 parent 767c306 commit 02defe3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 19 deletions.
25 changes: 25 additions & 0 deletions debugging/failure_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,36 @@ describe('modes of failure', function() {
browser.get('http://www.google.com');
}, 20000);

it('should fail within a promise', function () {
browser.get('index.html#/form');
var greeting = element(by.binding('{{greeting}}'));

greeting.getText().then(function(text) {
expect(text).toEqual('This is not what it equals');
});
});

it('should fail an assertion', function() {
browser.get('index.html#/form');

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

expect(greeting.getText()).toEqual('This is not what it equals');
});

it('should fail comparing a promise to another promise', function() {
browser.get('index.html#/form');

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

expect(greeting.getText()).toEqual(greeting.getAttribute('value'));
});


it('should fail because it throws an error', function() {
function foo() {
throw new Error('bar!');
}
foo();
});
});
31 changes: 17 additions & 14 deletions jasminewd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function wrapInControlFlow(globalFn) {
var thing = flow.execute(function() {
fn.call(jasmine.getEnv().currentSpec);
}).then(seal(done), function(e) {
e.stack = driverError.stack;
e.stack = driverError.stack + '\nAt async task:\n ' + e.stack;
done(e);
});
};
Expand Down Expand Up @@ -82,31 +82,34 @@ function wrapMatcher(matcher, actualPromise, not) {
matchError.stack = matchError.stack.replace(/ +at.+jasminewd.+\n/, '');
actualPromise.then(function(actual) {
var expected = originalArgs[0];

var expectation = expect(actual);
if (not) {
expectation = expectation.not;
}
var originalAddMatcherResult = expectation.spec.addMatcherResult;
var error = matchError;
expectation.spec.addMatcherResult = function(result) {
result.trace = error;
jasmine.Spec.prototype.addMatcherResult.call(this, result);
};

if (expected instanceof webdriver.promise.Promise) {
if (originalArgs.length > 1) {
throw error('Multi-argument matchers with promises are not '
+ 'supported.');
}
expected.then(function(exp) {
if (not) {
expect(actual).not[matcher](exp)
} else {
expect(actual)[matcher](exp);
}
expectation[matcher].apply(expectation, [exp]);
expectation.spec.addMatcherResult = originalAddMatcherResult;
});
} else {
var expectation = expect(actual);
if (not) {
expectation = expectation.not;
}
var origFn = expectation.spec.addMatcherResult;
var error = matchError;
expectation.spec.addMatcherResult = function(result) {
result.trace = error;
jasmine.Spec.prototype.addMatcherResult.call(this, result);
originalAddMatcherResult.call(this, result);
}
expectation[matcher].apply(expectation, originalArgs);
expectation.spec.addMatcherResult = origFn;
expectation.spec.addMatcherResult = originalAddMatcherResult;
}
});
};
Expand Down
22 changes: 17 additions & 5 deletions lib/protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -829,12 +829,24 @@ exports.filterStackTrace = function(text) {
if (!text) {
return text;
}
var jasmineFilename = 'node_modules/minijasminenode/lib/jasmine-1.3.1.js';
var seleniumFilename = 'node_modules/selenium-webdriver';
var substringsToFilter = [
'node_modules/minijasminenode/lib/',
'node_modules/selenium-webdriver',
'at Module.',
'at Object.Module.',
'at Function.Module',
'(timers.js:',
'jasminewd/index.js'
];
var lines = [];
text.split(/\n/).forEach(function(line){
if (line.indexOf(jasmineFilename) == -1 &&
line.indexOf(seleniumFilename) == -1) {
text.split(/\n/).forEach(function(line) {
var include = true;
for (var i = 0; i < substringsToFilter.length; ++i) {
if (line.indexOf(substringsToFilter[i]) !== -1) {
include = false;
}
}
if (include) {
lines.push(line);
}
});
Expand Down

0 comments on commit 02defe3

Please sign in to comment.