Coverage report of built app doesn't map to source files
See original GitHub issueLink to bug demonstration repository
I think I followed the docs correctly, but it’s certainly possible I missed a step 🤣
Expected Behavior
According to this, running a coverage report for a built app should map back to original source files.
Steps taken in above repo:
- Create empty app using
create-react-app - Build app, which generates sourcemaps
- Following these docs, instrument build output using
nyc instrument ./static ./static-i - Swap
staticdirectories so instrumented code is served - Run automated tests, aggregating
window.__coverage__ - Following these docs, dump coverage data to
.nyc_output/out.json - Run
nyc report --reporter=html
Observed Behavior
The report shows coverage for built files, not source files.
Troubleshooting steps
- still occurring when I put
cache: falsein my nyc config
Environment Information
System:
OS: macOS 10.14.5
CPU: (4) x64 Intel(R) Core(TM) i7-7567U CPU @ 3.50GHz
Memory: 242.63 MB / 16.00 GB
Binaries:
Node: 10.13.0 - /usr/local/bin/node
Yarn: 1.7.0 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:11 (2 by maintainers)
Top Results From Across the Web
Files not showing in Codecov (Fixing Paths)
This approach is how Codecov is able to correctly map coverage information in your uploaded coverage reports to the corresponding files in ...
Read more >Can't find source maps for Karma + Jasmine + TypeScript + ...
Now my tests run, there are no errors in the console, and I have a coverage report of the original TypeScript files!
Read more >4 Reasons Why Your Source Maps are Broken - Sentry Blog
4 Reasons Why Your Source Maps are Broken · Missing or incorrect source map directive · Missing original source files · Bad source...
Read more >Publish code coverage results v1 task - Microsoft Learn
Specifying a path to source files is required when coverage XML reports don't contain an absolute path to source files. For example, JaCoCo ......
Read more >Debug Angular apps in production without revealing source ...
We can see that no comment is added to the end of the file. Therefore the browser will not attempt to fetch source...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@bcoe sure thing: https://github.com/evanbb/nyc-instrument-and-report-bug
I stepped into it a bit, and it looked like the reporting logic is trying to reload the sourcemaps from cache here:
https://github.com/istanbuljs/nyc/blob/master/index.js#L567
However, the fileReport doesn’t even have a
contentHashproperty on it, so the check below fails:https://github.com/istanbuljs/nyc/blob/master/lib/source-maps.js#L43
Maybe something else needs to be done during instrumentation that I am missing. I stepped through the instrumentation command a bit as well, and although the sourcemaps were correctly found on disk during instrumentation, there was nothing written to the
node_modules/.cache/directory.I hacked it and manually wrote the corresponding files where they would have been in the cache directory, which caused the report to generate (almost) correctly: the report excluded
node_modulesand the rootindex.htmlfile reported correct numbers for original source files, but viewing the coverage page for a single source file displayed the error below:So something is definitely still missing…
I’m having the same problem.
When using
nyc instrument, thewindow.__coverage__is generated for the compiled files instead of source files.nyc reportthen shows empty report because thewindow.__coverage__values does not havecontentHash, onlyhash.I’ve also tried adding the instrumentation during the build step using
babel-plugin-istanbul. Using this approach,window.__coverage__is generated for the correct source files. However,nyc reportagain shows empty report because even in this case,window.__coverage__does not havecontentHashvalue.So I think we have two separate issues
nyc instrumentprocess source maps?How to makenyc reportaccepts coverage data stored inwindow.__coverage__?Edit: The issue with
nyc reportcan be bypassed by setting--exclude-after-remaptofalseso that it will ignore the problem with source maps.