-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
collectCoverage breaks TypeScript source stepping #5739
Comments
Note: The repo has been updated with decorators to prove a separate ts-jest line reporting issue. This issue is still reproducible with and without the decorators. |
Is this still an issue with the latest Jest and ts-jest? |
Yes, it is still an issue. I just tested with jest 23.6.0. I upgraded the test project as well. |
@huafu ideas? |
I first thought it was related to: babel/babel#6577 but after some tests doesn't seem to be (@SimenB you can confirm that bare js instrumented thru jest do can be debugged step by step when coverage is on right?). In ts-jest we do patch it, but only if babel is required. I tried to patch it beforehand without success. We do have e2e tests running over multiple versions of jest, babel and typescript for source mapping and then coverage, but I believe we do not have for both together, will drop an eye tommo. @mikebm can you open an issue on ts-jest with the link to your repo, I'll try to look at it asap. We're about to publish a new release but it'll wait if this is indeed ts-jest related and if it can get fixed quickly. BTW, your jest config can be simplified a lot @mikebm: {
"preset": "ts-jest",
"automock": true,
"collectCoverage": true,
"coverageDirectory": "<rootDir>/coverage/jest",
"coverageReporters": ["lcov", "json"],
"resetMocks": true,
"resetModules": true,
"testResultsProcessor": "jest-junit-reporter"
} |
Ok so this is a jest bug and not ts-jest bug. First here you're losing the input source maps in case it's not inlined but in the Then even if you had the source maps inlined, it'd be lost anyway there: ...where I'll try to provide a PR here soon. Update: the title of this issue should be: |
There's probably a reason why we don't factor in the source map in that case. @jwbay @aaronabramov do you know if there are? |
@SimenB any news on this? I meant, I'd be happy to provide a PR but I'm not gonna try if there is a good reason for it to be like that ;-) |
Feel free to send a PR! I'm not sure how it works, but if we're able to show it's more correct, no reason not to merge it 🙂 |
@huafu any chance of doing the PR? |
@ruiaraujo I actually had to run on another thing, and my project to hurry to finish. I have started a PR, AFAIR it was not as hard as I thought, ...was harder. So no, not finished, and now can't even remember what was the issue I was stuck with. FYI this is my branch, but I think I started again from sratch locally. Anyway, could give you the idea of what should be done. I'm sorry it's not in my priority because you can always run without coverage on your local while debugging and add |
Just curious if this is still being worked on. Looks like the code was refactored some over the past few months, so that the ScriptTransformer.ts is in the jest-transform package. For now will go with the workaround but would like to see an overall fix. |
Looking at this a bit since I tend to run into it. If you wire it up to push the instrumented sourceMap into cache, you get correct stack traces for errors in the code under test. Debugging in code under test works if you additionally request an inline sourceMap in the instrumented code (sourceMaps: 'both' instead of true). Currently just have a mess of a local POC branch but this is working how I expect it to. Hope to get something pushed this week. |
Created PR #9460 to address this - I can debug transformed typescript code under test and stack traces emitted from code under test correctly correspond to source lines. There isn't any obvious harm to existing functionality. |
Had to revert the fix due to a regression, so reopening this one |
Pushing the source maps (between source and instrumented code with coverage enabled) to Jest's cache for non-transformed code seems to break coverage reporting. It's certainly possible to go back to only pushing out source maps for transformed file, this line in the reverted PR could be this instead: This puts back coverage for untransformed files, although stack traces of errors from the files can pop out with the line numbers from the instrumented code. This seems to be on par with One thing I'm seeing here is that there's a I can disable this here and restore coverage reporting although I don't know if this is safe to do. |
If you can remove it and coverage is still correct that sounds a good path forward. It exists exactly to map coverage correctly when source maps are in play. It used to be a top level option to jest, but was moved to be inferred in #5177. which contains a bit of useful discussion. |
Opened up a new PR here, the main difference is that We seem to get all of the improvements for debugging and stack traces of the original PR, without doing harm to non-transformed coverage. |
This is a workaround since enabling coverage breaks sourceMaps. See: kulshekhar/ts-jest#917 See: jestjs/jest#5739
This is a workaround since enabling coverage breaks sourceMaps. See: kulshekhar/ts-jest#917 See: jestjs/jest#5739
This is a workaround since enabling coverage breaks sourceMaps. See: kulshekhar/ts-jest#917 See: jestjs/jest#5739
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Do you want to request a feature or report a bug?
BUG
What is the current behavior?
When collectCoverage is set to true, then source stepping no longer functions correctly.
Steps:
git clone https://github.com/mikebm/jestbug.git
cd jestbug
npm install
Debug the ./tests/component.test.ts file. Attempt to step through the executeSomeLogic call on test 'should return 5'.
What is the expected behavior?
When stepping through the executeSomeLogic function, your debugger should show the correct line that you are on.
Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.
Node v8.9.0
Jest 22.4.2
npm 5.6.0
The text was updated successfully, but these errors were encountered: