Skip to content

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

@juliemr

Description

@juliemr

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions