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

TypeScript Line Numbers From Unit Tests Fail to Use sourceMaps #1531

Closed
ghost opened this issue Jun 27, 2019 · 5 comments
Closed

TypeScript Line Numbers From Unit Tests Fail to Use sourceMaps #1531

ghost opened this issue Jun 27, 2019 · 5 comments
Assignees

Comments

@ghost
Copy link

ghost commented Jun 27, 2019

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();
});

  1. run command:
    ng test

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

@vsavkin vsavkin added this to the next milestone Jul 9, 2019
@wesleygrimes
Copy link
Contributor

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.

@wesleygrimes
Copy link
Contributor

wesleygrimes commented Jul 12, 2019

This appears to be a known issue with ts-jest and I have added a reproduction to the issue at kulshekhar/ts-jest#917 (comment)

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

@ghost
Copy link
Author

ghost commented Jul 12, 2019

Thanks - that unblocks us until the fix is found!

@wesleygrimes
Copy link
Contributor

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

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants