feat(learn): Collecting code coverage
Description
This PR introduces a learning article on collecting code coverage in Node.js. However, it should not be merged until support for thresholds is included in the next semver-minor release, which is expected to be next week.
Related Issues
Support for code coverage: https://github.com/nodejs/node/pull/46017 Support for code coverage inclusion/exclusion: https://github.com/nodejs/node/pull/53553 Support for code coverage thresholds: https://github.com/nodejs/node/pull/54429
Check List
- [x] I have read the Contributing Guidelines and made commit messages that follow the guideline.
- [x] I have run
npm run formatto ensure the code follows the style guide. - [x] I have run
npm run testto check if all tests are passing. - [x] I have run
npx turbo buildto check if the website builds without errors. - [N/A] I've covered new added functionality with unit tests if necessary.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
| Name | Status | Preview | Updated (UTC) |
|---|---|---|---|
| nodejs-org | ✅ Ready (Inspect) | Visit Preview | Mar 22, 2025 1:36pm |
This is currently marked as draft until the next semver-minor release of Node.js
https://nodejs-org-git-fork-redyetidev-code-coverage-learn-openjs.vercel.app/en/learn/test-runner/collecting-code-coverage
Deployment failed with the following error:
The provided GitHub repository does not contain the requested branch or commit reference. Please ensure the repository is not empty.
I've undrafted this, as the release proposal for v22.8.0 is ready at https://github.com/nodejs/node/pull/54560, but it still shouldn't land until that does.
The expected release date is ~~2024-08-26~~ 2024-09-02
Unit Test Coverage Report
| Lines | Statements | Branches | Functions |
|---|---|---|---|
| 88.75% (742/836) | 76.1% (242/318) | 87.65% (142/162) |
Unit Test Report
| Tests | Skipped | Failures | Errors | Time |
|---|---|---|---|---|
| 182 | 0 :zzz: | 0 :x: | 0 :fire: | 6.096s :stopwatch: |
Can we have last review form @nodejs/test_runner
I think this is okay to land once v22.8.0 releases, as it specifies that the --experimental-code-coverage command is needed, indicating that it is experimental. Would you like me to add a notice at the beginning that this is experimental, or just hold off until it's stabilized?
I think it's better to hold off until it's stable.
Is there an ETA for the stabilization of it?
IMO code coverage (w/o the --enable-source-maps flag) is pretty stable. I haven't seen many bugs with it in a while.
I asked a few weeks ago, and it was pointed out that statement coverage isn't supported, however, I'm not sure if that's in the plans for the immediate future of code coverage.
The original issue tracking the stability has been closed as completed, as all tasks were completed, which might mean it's ready to be stable. I've left a comment asking.
I'm fine keeping this open for the meantime, the problem is it becoming stale.
I'm also happy to close and reopen it, as chances are there will be some significant changes to the coverage reporter before stabilization, and this only collecting merge conflicts.
It's still experimental, but it's more stable, so I also think this can be merged.
@mcollina are you still blocking?
(I'll resolve the conflicts later today)
Lighthouse Results
| URL | Performance | Accessibility | Best Practices | SEO | Report |
|---|---|---|---|---|---|
| /en | 🟢 93 | 🟢 100 | 🟢 100 | 🟢 91 | 🔗 |
| /en/about | 🟢 100 | 🟢 100 | 🟢 100 | 🟢 91 | 🔗 |
| /en/about/previous-releases | 🟢 100 | 🟢 100 | 🟢 100 | 🟢 92 | 🔗 |
| /en/download | 🟢 92 | 🟢 100 | 🟢 100 | 🟢 91 | 🔗 |
| /en/blog | 🟢 99 | 🟢 100 | 🟢 96 | 🟢 92 | 🔗 |
Article published: https://nodejs.org/en/learn/test-runner/collecting-code-coverage