Skip to content
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

Support specifying "root directory" for source files when generating coverage reports #1470

Open
G-Rath opened this issue Jun 6, 2022 · 0 comments

Comments

@G-Rath
Copy link

G-Rath commented Jun 6, 2022

This is stemming from jestjs/jest#7176 which I've created a jest-free reproduction for here: https://github.com/G-Rath/jest-istanbul-repo

I didn't open the original issue so it's possible I've missed something or that this doesn't completely solve the Jest issue, but this overall does seem like a good enhancement for nyc.

Currently when generating a coverage report nyc seems to base it on the first common root of the files in the report e.g. in my reproduction there are two coverage maps that were generated from the original reproduction repo (on the jest issue) just with no code in the index.js and file.js files to make the maps as small as possible - coverage-map-one-file.json is generated by running jest file --coverage and coverage-map-two-file.json is generated by running jest --coverage.

If you call index.js coverage-map-one-file.json it'll generate an html coverage report with this structure:

coverage
├── base.css
├── block-navigation.js
├── favicon.png
├── file.js.html
├── index.html
├── prettify.css
├── prettify.js
├── sort-arrow-sprite.png
└── sorter.js

0 directories, 9 files

If you call index.js coverage-map-two-file.json it'll generate an html coverage report with this structure:

coverage
├── base.css
├── block-navigation.js
├── favicon.png
├── index.html
├── index.js.html
├── prettify.css
├── prettify.js
├── sort-arrow-sprite.png
├── sorter.js
└── src
    ├── file.js.html
    └── index.html

1 directory, 11 files

This can be confusing, because the contents of the coverage dir are not automatically wiped (at least by nyc) so if you're refreshing the html report in your browser you could end up seeing the old coverage, and likewise can run into 404s if it is wiped.

The desired behaviour (which this issue is about) is that both of these coverage reports should have file.js.html located in src, which I believe can be achieved by allowing nyc to be passed a rootDir option that sets that "first common root" - that way external tools like jest (who typically know where the root of the project is) can have nyc generate a consistent output regardless of what files are actually being covered.

I can help try and implement this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant