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

NYC checkCoverage doesn't have a way to throw error when insufficient coverage met #1539

Open
1 task done
sh977218 opened this issue Dec 15, 2023 · 0 comments
Open
1 task done

Comments

@sh977218
Copy link

sh977218 commented Dec 15, 2023

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

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