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
The line number of uncaught errors and console logs are a hundred or more lines off.
It looks like "ng test" isn't loading source map files.
In app.component.ts - add the following (to your class):
foo():void{
throw new Error('test');
}
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();
});
run command:
ng test
Note that the line number is off by over a hundred - example:
at AppComponent.foo (src/app/app.component.ts:196:11)
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",
● 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)
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.