-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Fix ngMock window.inject() stack trace reporting on PhanthomJS for master branch #13593
Conversation
5de8d30
to
e3eb4bd
Compare
Add support for collecting current stack trace information in browsers (e.g. PhantomJS) that do not automatically store the current stack trace information in a newly created `Error` object's `stack` property, but only add it there once the `Error` gets thrown. The original implementation works fine in Firefox & Chrome, but fails on PhantomJS where it, for example, breaks karma's error reporting in cases when an exception for thrown in a test like the following: ``` it('the holy crusade', inject(function () { var x = {}; x.holyGrail(); })); ``` where the ngMock `inject()` implementation would incorrectly add the word `undefined` to the end of the collected error stack trace information, thus causing the main error description to be reported back to karma as `undefined`. The whole `Error.stack` property and its behaviour is not standardized so there is no one true implementation that we can assume is used by all angular compatible browsers. MSDN JavaScript `stack Property (Error) (JavaScript)` docs found at http://msdn.microsoft.com/en-us/library/windows/apps/hh699850.aspx also seem to match the PhantomJS implementation.
Angular's ngMock inject() function, when called outside of a test spec context will not directly call the provided callback but will instead return a wrapper function to call the provided function at a later time, presumably while in some test spec context. And if that is the case, Angular would like to include the information on the inject() calling location to be included in the thrown error's stack trace information, so it manually appends it to the ones included in the actual error's stack trace. The added test makes sure this functionality: - works as expected in browsers supporting JavaScript stack trace collection, e.g. Chrome, Firefox, IE10+, Opera & PhantomJS - does not add any bogus stack track information in browsers that do not support JavaScript stack trace collection, e.g. IE8 or IE9 Closes angular#13591
e3eb4bd
to
0e52aeb
Compare
Could this pull request be merged? It's a simple bug-fix, well commented and with relevant tests added. Leaving it hanging here just makes it attract conflicts. 😟 |
…omJS Add support for collecting current stack trace information in browsers (e.g. IE10+, PhantomJS) that do not automatically store the current stack trace information in a newly created `Error` object's `stack` property, but only add it there once the `Error` gets thrown. The original implementation works fine in Firefox & Chrome, but fails on IE10+ and PhantomJS where it, for example, breaks Karma's error reporting in cases when an exception is thrown in a test like the following: ``` it('the holy crusade', inject(function() { var x = {}; x.holyGrail(); })); ``` In this case, the ngMock `inject()` implementation would incorrectly add the word `undefined` at the end of the collected error stack trace information, thus causing the main error description to be reported back to Karma as `undefined`. The added test makes sure this functionality: - works as expected in browsers supporting JavaScript stack trace collection, e.g. Chrome, Firefox, IE10+, Opera & PhantomJS - does not add any bogus stack track information in browsers that do not support JavaScript stack trace collection, e.g. IE9 Fixes #13591 Closes #13592 Closes #13593
…omJS Add support for collecting current stack trace information in browsers (e.g. IE10+, PhantomJS) that do not automatically store the current stack trace information in a newly created `Error` object's `stack` property, but only add it there once the `Error` gets thrown. The original implementation works fine in Firefox & Chrome, but fails on IE10+ and PhantomJS where it, for example, breaks Karma's error reporting in cases when an exception is thrown in a test like the following: ``` it('the holy crusade', inject(function() { var x = {}; x.holyGrail(); })); ``` In this case, the ngMock `inject()` implementation would incorrectly add the word `undefined` at the end of the collected error stack trace information, thus causing the main error description to be reported back to Karma as `undefined`. The added test makes sure this functionality: - works as expected in browsers supporting JavaScript stack trace collection, e.g. Chrome, Firefox, IE10+, Opera & PhantomJS - does not add any bogus stack track information in browsers that do not support JavaScript stack trace collection, e.g. IE9 Fixes #13591 Closes #13592 Closes #13593
Cleaned it up a bit and merged. @jurko-gospodnetic, it would be great if you could make sure it works as expected on PhantomJS. |
@gkalpak hi & thanks for merging. I ran the code through PhantomJS and it works as expected. I also ran angular's There are some other parts that fail when you run the full angular test suite fails on PhantomJS, but I did not want to get into that at this time. Btw. nice catch with throwing and catching not constructing a different error instance but updating the |
Thx for getting back !
Yeah, PhantomJS is not use of the officially supported browsers, so we don't run tests against it and our testsuite is not 100% "PhantomJS-compatible". But many people are using it in their projects without a problem (including myself). |
Fixes & adds a tests for issue #13591 for the angular
master
branch.This does the same work as pull request #13592 does on the angular
1.4.x
branch.