Nx: TypeScript Line Numbers From Unit Tests Fail to Use sourceMaps

Created on 28 Jun 2019  ·  4Comments  ·  Source: nrwl/nx

Expected Behavior

When "ng test" is used and either an uncaught error or console.log occurs outside of a test file (exp: in a component file) - the line numbers do not use sourceMaps

Current Behavior

The line number of uncaught errors and console logs are a hundred or more lines off.

Failure Information (for bugs)

It looks like "ng test" isn't loading source map files.

Steps to Reproduce

  1. run command:
    npx --ignore-existing create-nx-workspace nx-dev-test
  2. run command:
    cd nx-dev-test
  3. run command:
    ng add @nrwl/angular --defaults
  4. run command:
    ng g @nrwl/angular:application quicky
  5. In app.component.ts - add the following (to your class):
    foo():void{
    throw new Error('test');
    }

  6. In app.component.spec.ts add a new unit test to call your new function:

    it('check line number for crash', () => {
    const appComponent:AppComponent = new AppComponent();
    appComponent.foo();
    });

  7. run command:
    ng test

  8. Note that the line number is off by over a hundred - example:
    at AppComponent.foo (src/app/app.component.ts:196:11)

Context

Please provide any relevant information about your setup:

npx: 6.9.0
"@angular/cli": "8.0.0"
angular.json: default file generated using steps provided
"@angular-devkit/build-angular": "^0.800.0",

Failure Logs

● AppComponent › check line number for crash

test



  at AppComponent.foo (src/app/app.component.ts:211:11)
  at src/app/app.component.spec.ts:34:20
  at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (../../node_modules/zone.js/dist/zone.js:391:26)
  at ProxyZoneSpec.Object.<anonymous>.ProxyZoneSpec.onInvoke (../../node_modules/zone.js/dist/proxy.js:129:39)
  at ZoneDelegate.Object.<anonymous>.ZoneDelegate.invoke (../../node_modules/zone.js/dist/zone.js:390:52)
  at Zone.Object.<anonymous>.Zone.run (../../node_modules/zone.js/dist/zone.js:150:43)
  at Object.<anonymous> (../../node_modules/jest-preset-angular/zone-patch/index.js:52:27)

Other

bug

All 4 comments

Narrowed this down to an issue with setting collectCoverage: true in jest.config.js. If flipped to false correct line number is reported. Digging further to resolve.

This appears to be a known issue with ts-jest and I have added a reproduction to the issue at https://github.com/kulshekhar/ts-jest/issues/917#issuecomment-510980437

Here's the small reproduction I created with a detailed readme: https://github.com/wesleygrimes/ts-jest-coverage-incorrect-line-numbers/blob/master/README.md

Thanks - that unblocks us until the fix is found!

You're welcome! We will get it resolved but I am glad you have a workaround.

Was this page helpful?
0 / 5 - 0 ratings