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

Conversation

jurko-gospodnetic
Copy link
Contributor

Fixes & adds a tests for issue #13591 for the angular 1.4.x branch.

This does the same work as pull request #13593 does on the angular master branch.

@jurko-gospodnetic jurko-gospodnetic changed the title Fix ng mock inject stack trace reporting on phanthom js Fix ngMock window.inject() stack trace reporting on PhanthomJS Dec 20, 2015
@jurko-gospodnetic jurko-gospodnetic force-pushed the fix-ngMock-inject-stack-trace-reporting-on-PhanthomJS branch 2 times, most recently from 189bff2 to 36ab100 Compare December 20, 2015 08:38
@jurko-gospodnetic jurko-gospodnetic changed the title Fix ngMock window.inject() stack trace reporting on PhanthomJS Fix ngMock window.inject() stack trace reporting on PhanthomJS for 1.4.x branch Dec 20, 2015
@jurko-gospodnetic jurko-gospodnetic force-pushed the fix-ngMock-inject-stack-trace-reporting-on-PhanthomJS branch from 36ab100 to e59540a Compare December 20, 2015 08:55
@Narretz Narretz modified the milestone: Backlog Jan 6, 2016
@Narretz Narretz self-assigned this Feb 28, 2016
@jurko-gospodnetic
Copy link
Contributor Author

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. 😟

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
@jurko-gospodnetic jurko-gospodnetic force-pushed the fix-ngMock-inject-stack-trace-reporting-on-PhanthomJS branch from e59540a to 6c45811 Compare April 8, 2016 14:27
@gkalpak gkalpak closed this in 92c3b75 Apr 9, 2016
gkalpak pushed a commit that referenced this pull request Apr 9, 2016
…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
gkalpak pushed a commit that referenced this pull request Apr 9, 2016
…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
@jurko-gospodnetic jurko-gospodnetic deleted the fix-ngMock-inject-stack-trace-reporting-on-PhanthomJS branch April 11, 2016 06:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants