Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Karma-jasmine adapter mangles stack traces from Zone.js (occasionally) #120

Open
juliemr opened this issue Apr 27, 2016 · 2 comments
Open

Comments

@juliemr
Copy link

juliemr commented Apr 27, 2016

The Karma reporter's formatFailedStep function is turning decent errors with my stack which includes Zone.js into a useless clip. This is because of the processing heuristics for PhantomJS stack traces.

My original step has message:

"Failed: Uncaught (in promise): EXCEPTION: Error in ./MyFooterComp class MyFooterComp - inline template:2:5
ORIGINAL EXCEPTION: TypeError: Cannot read property 'subscribe' of undefined
ORIGINAL STACKTRACE:
TypeError: Cannot read property 'subscribe' of undefined
    at new RouterLink (http://localhost:9876/base/node_modules/angular2/bundles/router.dev.js:1447:19)
    at AppView._View_MyFooterComp0.createInternal (MyFooterComp.template.js:31:26)
    at AppView.create (http://localhost:9876/base/node_modules/angular2/bundles/angular2.js:22641:23)
    at AppView._View_TestComponent0.createInternal (TestComponent.template.js:18:14)
    at AppView.create (http://localhost:9876/base/node_modules/angular2/bundles/angular2.js:22641:23)
    at AppView._View_TestComponent_Host0.createInternal (TestComponent_Host.template.js:17:14)
    at AppView.create (http://localhost:9876/base/node_modules/angular2/bundles/angular2.js:22641:23)
    at ComponentFactory.create (http://localhost:9876/base/node_modules/angular2/bundles/angular2.js:7668:34)
    at http://localhost:9876/base/node_modules/angular2/bundles/angular2.js:4123:45
    at ZoneDelegate.invoke (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:349:29)
    at AsyncTestZoneSpec.onInvoke (http://localhost:9876/base/node_modules/zone.js/dist/async-test.js:76:44)
    at ZoneDelegate.invoke (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:348:35)
    at Zone.run (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:242:44)
    at http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:597:58
    at ZoneDelegate.invokeTask (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:382:38)
    at Zone.runTask (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:282:48)
    at drainMicroTaskQueue (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:500:36)
    at XMLHttpRequest.ZoneTask.invoke (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:452:22)
ERROR CONTEXT:
[object Object]"

and stack:

Error: Failed: Uncaught (in promise): EXCEPTION: Error in ./MyFooterComp class MyFooterComp - inline template:2:5
ORIGINAL EXCEPTION: TypeError: Cannot read property 'subscribe' of undefined
ORIGINAL STACKTRACE:
TypeError: Cannot read property 'subscribe' of undefined
    at new RouterLink (http://localhost:9876/base/node_modules/angular2/bundles/router.dev.js:1447:19)
    at AppView._View_MyFooterComp0.createInternal (MyFooterComp.template.js:31:26)
    at AppView.create (http://localhost:9876/base/node_modules/angular2/bundles/angular2.js:22641:23)
    at AppView._View_TestComponent0.createInternal (TestComponent.template.js:18:14)
    at AppView.create (http://localhost:9876/base/node_modules/angular2/bundles/angular2.js:22641:23)
    at AppView._View_TestComponent_Host0.createInternal (TestComponent_Host.template.js:17:14)
    at AppView.create (http://localhost:9876/base/node_modules/angular2/bundles/angular2.js:22641:23)
    at ComponentFactory.create (http://localhost:9876/base/node_modules/angular2/bundles/angular2.js:7668:34)
    at http://localhost:9876/base/node_modules/angular2/bundles/angular2.js:4123:45
    at ZoneDelegate.invoke (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:349:29)
    at AsyncTestZoneSpec.onInvoke (http://localhost:9876/base/node_modules/zone.js/dist/async-test.js:76:44)
    at ZoneDelegate.invoke (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:348:35)
    at Zone.run (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:242:44)
    at http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:597:58
    at ZoneDelegate.invokeTask (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:382:38)
    at Zone.runTask (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:282:48)
    at drainMicroTaskQueue (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:500:36)
    at XMLHttpRequest.ZoneTask.invoke (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:452:22)
ERROR CONTEXT:
[object Object]
    at stack (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1482:17)
    at buildExpectationResult (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1452:14)
    at Spec.Env.expectationResultFactory (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:583:18)
    at Spec.addExpectationResult (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:324:34)
    at Env.fail (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:894:25)
    at AsyncTestZoneSpec.next.fail [as _failCallback] (http://localhost:9876/base/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:1806:19)
    at AsyncTestZoneSpec.onHandleError (http://localhost:9876/base/node_modules/zone.js/dist/async-test.js:86:23)
    at ZoneDelegate.handleError (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:353:40)
    at Zone.runGuarded (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:259:45)
    at _loop_1 (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:513:52)
    at drainMicroTaskQueue (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:520:22)
    at XMLHttpRequest.ZoneTask.invoke (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:452:22)"

But after Karma process, the output is

at XMLHttpRequest.ZoneTask.invoke (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:452:22)
    at AsyncTestZoneSpec.onHandleError (http://localhost:9876/base/node_modules/zone.js/dist/async-test.js:86:23)
    at ZoneDelegate.handleError (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:353:40)
    at Zone.runGuarded (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:259:45)
    at _loop_1 (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:513:52)
    at drainMicroTaskQueue (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:520:22)

The offending issue seems to be that we trigger this line (

// Stack entry is already in the message,
) since the line XMLHttpRequest.ZoneTask.invoke (http://localhost:9876/base/node_modules/angular2/bundles/angular2-polyfills.js:452:22) appears in both the message and the stack.

It seems like the heuristic should be to remove the original step's message only if the ENTIRE thing appears in the stack trace, instead of just one line.

@juliemr juliemr changed the title Karma-jasmine adapter mangles stack traces from Zone.js Karma-jasmine adapter mangles stack traces from Zone.js (occasionally) Apr 27, 2016
@ccurrens
Copy link

ccurrens commented Apr 30, 2016

This also happens for some errors thrown by angularjs. The most common time I've seen it is when a module is referenced but never defined. The result is the same, the actual message should be:

Chrome 49.0.2623 (Windows 10 0.0.0) myApp.view1 module view1 controller should .... FAILED
    Error: [$injector:modulerr] Failed to instantiate module myApp.view1 due to:
    Error: [$injector:modulerr] Failed to instantiate module missingmodule due to:
    Error: [$injector:nomod] Module 'missingmodule' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
    http://errors.angularjs.org/1.4.10/$injector/nomod?p0=missingmodule
        at C:/repos/phantomjsbug/app/bower_components/angular/angular.js:68:12
        at C:/repos/phantomjsbug/app/bower_components/angular/angular.js:2012:17
        at ensure (C:/repos/phantomjsbug/app/bower_components/angular/angular.js:1936:38)
        at module (C:/repos/phantomjsbug/app/bower_components/angular/angular.js:2010:14)
        at C:/repos/phantomjsbug/app/bower_components/angular/angular.js:4472:22
        at forEach (C:/repos/phantomjsbug/app/bower_components/angular/angular.js:341:20)
        at loadModules (C:/repos/phantomjsbug/app/bower_components/angular/angular.js:4456:5)
        at C:/repos/phantomjsbug/app/bower_components/angular/angular.js:4473:40
        at forEach (C:/repos/phantomjsbug/app/bower_components/angular/angular.js:341:20)
        at loadModules (C:/repos/phantomjsbug/app/bower_components/angular/angular.js:4456:5)
    http://errors.angularjs.org/1.4.10/$injector/modulerr?p0=missingmodule&p1=[Elided]
        at C:/repos/phantomjsbug/app/bower_components/angular/angular.js:68:12
        at C:/repos/phantomjsbug/app/bower_components/angular/angular.js:4495:15
        at forEach (C:/repos/phantomjsbug/app/bower_components/angular/angular.js:341:20)
        at loadModules (C:/repos/phantomjsbug/app/bower_components/angular/angular.js:4456:5)
        at C:/repos/phantomjsbug/app/bower_components/angular/angular.js:4473:40
        at forEach (C:/repos/phantomjsbug/app/bower_components/angular/angular.js:341:20)
        at loadModules (C:/repos/phantomjsbug/app/bower_components/angular/angular.js:4456:5)
        at Object.createInjector [as injector] (C:/repos/phantomjsbug/app/bower_components/angular/angular.js:4381:11)
        at Object.workFn (C:/repos/phantomjsbug/app/bower_components/angular-mocks/angular-mocks.js:2507:52)
    http://errors.angularjs.org/1.4.10/$injector/modulerr?p0=myApp.view1&p1=[Elided]
        at C:/repos/phantomjsbug/app/bower_components/angular/angular.js:68:12
        at C:/repos/phantomjsbug/app/bower_components/angular/angular.js:4495:15
        at forEach (C:/repos/phantomjsbug/app/bower_components/angular/angular.js:341:20)
        at loadModules (C:/repos/phantomjsbug/app/bower_components/angular/angular.js:4456:5)
        at Object.createInjector [as injector] (C:/repos/phantomjsbug/app/bower_components/angular/angular.js:4381:11)
        at Object.workFn (C:/repos/phantomjsbug/app/bower_components/angular-mocks/angular-mocks.js:2507:52)

It gets truncated down to this:

PhantomJS 2.1.1 (Windows 8 0.0.0) myApp.view1 module view1 controller should .... FAILED
        C:/repos/phantomjsbug/app/bower_components/angular/angular.js:4496:53
        forEach@C:/repos/phantomjsbug/app/bower_components/angular/angular.js:341:24
        loadModules@C:/repos/phantomjsbug/app/bower_components/angular/angular.js:4456:12
        createInjector@C:/repos/phantomjsbug/app/bower_components/angular/angular.js:4381:22
        workFn@C:/repos/phantomjsbug/app/bower_components/angular-mocks/angular-mocks.js:2507:60

I've found that karma-chrome-launcher will always show the entire error message, because step.stack is empty, so it doesn't modify step.message at all.

If it helps, I've created a repo here: https://github.com/ccurrens/angular-seed-phantomjsbug that can reproduce the bug every test run. You can run npm test to see the issue, npm run test-chrome to see expected output.

@maksimr
Copy link
Contributor

maksimr commented Apr 30, 2016

@ccurrens thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants