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 master branch.

This does the same work as pull request #13592 does on the angular 1.4.x branch.

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-on-master branch from e3eb4bd to 0e52aeb Compare April 8, 2016 14:14
@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. 😟

@gkalpak gkalpak assigned gkalpak and unassigned Narretz Apr 9, 2016
@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
@gkalpak
Copy link
Member

gkalpak commented Apr 9, 2016

Cleaned it up a bit and merged. @jurko-gospodnetic, it would be great if you could make sure it works as expected on PhantomJS.

@jurko-gospodnetic
Copy link
Contributor Author

@gkalpak hi & thanks for merging.

I ran the code through PhantomJS and it works as expected. I also ran angular's ngMock related test:jqlite test suite using PhantomJS and it passes and some custom added console.log() calls report not having stack information before throwing the error and having it after throwing & catching it, as expected.

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 stack in the original error object.

@gkalpak
Copy link
Member

gkalpak commented Apr 11, 2016

Thx for getting back !

There are some other parts that fail when you run the full angular test suite fails on PhantomJS

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

@jurko-gospodnetic jurko-gospodnetic deleted the fix-ngMock-inject-stack-trace-reporting-on-PhanthomJS-on-master branch April 11, 2016 06:47
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.

4 participants