Feature Request: Instrument option to generate a baseline coverage file
See original GitHub issueProblem
Currently when testing with files created by the standalone instrument command, if a file isn’t hit it will not produce a coverage output file. This can lead to untouched files being excluded from the coverage report. Istanbul handled this by being able to produce a baseline coverage file with content similar to that produced by running nyc --all=true /usr/bin/true
. When the baseline coverage file is included with test generated coverage files and fed to the reporter, files that aren’t hit during tests are included in the report.
In hindsight I think this was the problem being faced in #1044.
Proposal
Add an option to the instrument command, ‘baseline’, that will produce a baseline coverage output json file similar to that produced by running nyc --all=true /usr/bin/true
.
Workaround
You can generate a report that includes untouched files with:
- run
nyc --all <options> /usr/bin/true
against the uninstrumented code - store the output coverage file
- instrument the source
- run tests
- combine baseline and test coverage files
- report on combined coverage files
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:11 (11 by maintainers)
Top GitHub Comments
I’ll try and put together a demo project but it might take a little time as I’m seeing the issue on internal source that I can’t share without some redaction. I’ll drop it into a new issue as it’s a little off topic in here.
I’ve been thinking a little bit about this feature and it seems to me that we really want is what
nyc --all ...
currently does. We should implementnyc instrument --all
, then it’s quite reasonable to expect the two--all
commands to behave in the same way. No need for a separatebaseline
directory, the filename can stay<uuid>.json
and theprocessInfo
files would still be there if needed.This also simplifies the interface and the documentation.