If user enables test coverage with Jest then the sourcemaps are not correct.
Lines should be shown correctly, even if developer enables coverage report with Jest.
Github project: https://github.com/maxpolski/ts-react-jest/ Please kindly note that this is NOT my repository
Run jest with coverage option.
You will notice that the sourcemaps are not working correctly. To make sure, you can add console.log() in any React component and compare the line where console.log occured with the one displayed in the jest output.
Interestingly, sourcemaps work absolutely fine in test files, but not in source files.
I confirmed that this was the cause of my inability to debug tests via vscode-jest. Turning off code coverage allowed the sourcemaps to be built properly.
Any thoughts on the cause/fix? I started seeing this today. My index.ts file has around 100 lines but jest is reporting console.log calls on lines > 1000.
I can confirm that this is an issue for me as well.
It was driving me crazy because it also prevented debuggers from stepping through the code. Glad I found that I was not the only one experiencing this.
Can confirm, VSCode debugger reports line numbers >6000 in file with 300 lines and fails to hit breakpoints when using the ts-jest interpreter and jest test runner. Disabling code coverage appears to reduce or resolve the problem(s).
I am getting this problem as well when I turn on coverage. Looking through similar issues I found https://github.com/kulshekhar/ts-jest/issues/484 which has some commits to fix this same issue though, and I am using the latest build, so I am kind of confused...
Hi all,
I am having the same issue. I took some time and created a small repository that reproduces the issue: https://github.com/wesleygrimes/ts-jest-coverage-incorrect-line-numbers
I am seeing this issue as well with jest: 24.8.0 and ts-jest: 24.0.2.
jest.config.js:
module.exports = {
testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'],
transform: {
'^.+\\.(ts|js|html)$': 'ts-jest'
},
roots: ['<rootDir>/src'],
moduleFileExtensions: ['ts', 'js', 'html'],
collectCoverage: true,
coverageReporters: ['html']
};
We need collectCoverage enabled. Is there a fix planned for this? Would be happy to help with a PR if someone can point me in the right direction.
Thanks!
Was fixed in 23.1.2, see . But reproducible in:
jest 24.9.0 + ts-jest 24.0.2
jest 23.6.0 + ts-jest 23.10.5 (latest 23.* versions as of today)
Workaround for debugging:
collectCoverage from config--coverage to jest cli in test script of package.json:"test": "jest --config ./jestConfig.json --coverage"
any news on when this may be fixed? Being locked on v 23.1.2 is making moving to jest 24 a painful experience.
In order to get debugging to work, I removed "collectCoverage" from my jest configuration and instead changed my npm script to jest --coverage. Then, in VSCode's launch configuration I did not add that flag. Who needs coverage during debugging anyways? It also makes the test execution slower.
Of course, this is just a workaround until this is fixed.
I found a fix that works well for me. If you add --coverage false to the command line when the jest debugger is run, it works just fine. The solution is to add this block to your launch configuration in .vscode/launch.json:
{
"type": "node",
"request": "launch",
"name": "vscode-jest-tests",
"cwd": "${workspaceFolder}",
"args": ["--inspect-brk", "${workspaceRoot}/node_modules/.bin/jest", "--runInBand",
"--config", "--coverage", "false"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
This is not ts-jest issue. Please check related discussion in https://github.com/facebook/jest/issues/5739
Most helpful comment
I confirmed that this was the cause of my inability to debug tests via vscode-jest. Turning off code coverage allowed the sourcemaps to be built properly.