-
-
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
Improve source map handling when instrumenting transformed code (#5739) #9811
Conversation
35c82d4
to
c65d3c2
Compare
Thanks @mbpreble! Is |
@SimenB not as far as I can tell. It still appears to be checked in a couple of places to drive mapping behavior if Might be a candidate for breaking changes and removal down the line. This seems to leave behind some code paths which aren't exercised internally by Jest. |
@jwbay would love your thoughts on this one 🙂 |
@SimenB - new commit here to remove dead code that was gated by |
Codecov Report
@@ Coverage Diff @@
## master #9811 +/- ##
==========================================
+ Coverage 64.43% 64.50% +0.07%
==========================================
Files 290 291 +1
Lines 12376 12361 -15
Branches 3058 3057 -1
==========================================
Hits 7974 7974
+ Misses 3762 3745 -17
- Partials 640 642 +2
Continue to review full report at Codecov.
|
Oh yeah, this is lovely! This does make sense to me - There's a small conflict, mind merging or rebasing on master?
Can you add an integration test for this? Then snapshot the error which hopefully points to the correct thing. |
packages/jest-runtime/src/index.ts
Outdated
@@ -808,9 +808,6 @@ class Runtime { | |||
|
|||
if (transformedFile.sourceMapPath) { | |||
this._sourceMapRegistry[filename] = transformedFile.sourceMapPath; | |||
if (transformedFile.mapCoverage) { | |||
this._needsCoverageMapped.add(filename); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we delete the _needsCoverageMapped
property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pulled on this thread a bit more - we can remove the property and there's an entire getSourceMapInfo
function which collapses down into returning an empty object.
There was a call site in runTest
which used this to attach a sourceMaps
property to TestResult
, leading to some more apparently defunct code in coverage_reporter
.
Deleted a few more things here and added a couple more TODOs for deletion in Jest 26.
…rage - inputSourceMap should always be available.
fc78a83
to
472b882
Compare
Rebased on master and tracked down some more things to delete related to coverage mapping. Existing breaking change to |
This is a lot to catch up on, but I can say with confidence that when it comes to |
|
||
at Object.error (lib.ts:13:9) | ||
at Object.<anonymous> (__tests__/fails.ts:10:3) | ||
`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again @mbpreble, this is awesome stuff! |
Thanks for the help! |
…pshots * upstream/master: (39 commits) Prints the Symbol name into the error message with a custom asymmetric matcher (jestjs#9888) Show coverage of sources related to tests in changed files (jestjs#9769) fix: don't /// <reference types="jest" /> (jestjs#9875) noCodeFrame respects noStackTrace (jestjs#9866) chore: update example to [email protected] (jestjs#9746) Improve source map handling when instrumenting transformed code (jestjs#9811) Update .vscode/launch.json settings (jestjs#9868) chore: verify all packages have the same engine requirement (jestjs#9871) fix: pass custom cached realpath function to `resolve` (jestjs#9873) chore: mock stealthy-require in tests (jestjs#9855) chore: update resolve (jestjs#9872) chore: run CircleCI on node 14 (jestjs#9870) Add an option to vscode settings to always use workspace TS (jestjs#9869) fix(esm): handle parallel imports (jestjs#9858) chore: run CI on Node 14 (jestjs#9861) feat: add `@jest/globals` package for importing globals explici… (jestjs#9849) chore: bump resolve package (jestjs#9859) chore(runtime): simplify `createJestObjectFor` (jestjs#9857) chore: fix symlink creation failures on windows in tests (jestjs#9852) chore: skip mercurial tests when no hg installed (jestjs#9840) ...
…pshots * upstream/master: (39 commits) Prints the Symbol name into the error message with a custom asymmetric matcher (jestjs#9888) Show coverage of sources related to tests in changed files (jestjs#9769) fix: don't /// <reference types="jest" /> (jestjs#9875) noCodeFrame respects noStackTrace (jestjs#9866) chore: update example to [email protected] (jestjs#9746) Improve source map handling when instrumenting transformed code (jestjs#9811) Update .vscode/launch.json settings (jestjs#9868) chore: verify all packages have the same engine requirement (jestjs#9871) fix: pass custom cached realpath function to `resolve` (jestjs#9873) chore: mock stealthy-require in tests (jestjs#9855) chore: update resolve (jestjs#9872) chore: run CircleCI on node 14 (jestjs#9870) Add an option to vscode settings to always use workspace TS (jestjs#9869) fix(esm): handle parallel imports (jestjs#9858) chore: run CI on Node 14 (jestjs#9861) feat: add `@jest/globals` package for importing globals explici… (jestjs#9849) chore: bump resolve package (jestjs#9859) chore(runtime): simplify `createJestObjectFor` (jestjs#9857) chore: fix symlink creation failures on windows in tests (jestjs#9852) chore: skip mercurial tests when no hg installed (jestjs#9840) ...
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
This PR is motivated by issue #5739. There are a few issues around Jest's implementation of code coverage using
babel-plugin-istanbul
which are corrected hereThe change here ensures that source maps are explicitly passed along to the instrumenting process when dealing with transformed code, that the instrumented code includes an inline source map back to the original source, and that this source map is stored in Jest's cache.
Here we bypass a mechanism intended to map reported coverage back to the original source - this should be unnecessary as coverage will already refer to the original source in all cases where it's possible to do so.
Fixes #5739.
Test plan
I have a test repository containing both TS and JS test files and code. When I run the
master
version of Jest against this repository, I can confirm uncaught errors are reported using the wrong line numbers. I'm unable to hit a breakpoint in the TS code under test when debugging. The reported coverage appears correct:Running Jest with this change, line numbers for errors are corrected and it is possible to debug TS code under test. Errors are even shown in context. Note that no obvious harm has been done to coverage reporting for either the TS or JS files.