NYC checkCoverage doesn't have a way to throw error when insufficient coverage met
sh977218 opened this issue · comments
Peter Huang commented
Expected Behavior
In typescript, I import NYC from 'nyc', and generate report, check code coverage programmatically.
new NYC().checkCoverage(coverageThresholds) should have option to throw error at end, instead of just purely console.error
this is my example code:
import NYC from 'nyc'; //"nyc": "^15.1.0",
try {
const nycOutput = join(__dirname, '.', '.nyc_output');
const nycInstance = new NYC({
cwd: join(__dirname, '.'),
reportDir: `coverage-e2e`,
reporter: ['lcov', 'json', 'text-summary'],
});
await nycInstance.checkCoverage(coverageThresholds);
await nycInstance.report();
await fs.rm(nycOutput, { recursive: true, force: true });
} catch (e) {
// NYC doesn't throw error when coverage is not met. bug
console.error('Insufficient playwright code coverage!');
}
Observed Behavior
checkCoverage() only set process.exitCode = 1 when insufficient coverage met, but in my use case, process is not passed into NYC class.
Troubleshooting steps
- still occurring when I put
cache: false
in my nyc config
Environment Information
# paste the output here