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
test_runner: added coverage threshold support for tests #51182
base: main
Are you sure you want to change the base?
Conversation
|
Review requested:
|
|
I think this should also set the exit code to a nonzero value such that CI systems will mark the job as failed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree on the exit code; also, coverage always has 4 metrics, lines, functions, branches, and statements.
working on it 👍🏼 |
bfcfe72
to
52100c7
Compare
lib/internal/test_runner/test.js
Outdated
| const failedCoverage = ArrayPrototypeFilter( | ||
| ObjectKeys(coverage.threshold), (key) => !coverage.threshold[key]); | ||
| if (failedCoverage.length > 0) { | ||
| console.error(`test coverage failed for ${ArrayPrototypeJoin(failedCoverage, ', ')}`); | ||
| process.exit(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here I added the logic to exit the test when coverage threshold doesn't match.
running test will be exited with status code 1.
output:
✔ hello test (0.64525ms)
✔ sub test (0.078625ms)
ℹ tests 2
ℹ suites 0
ℹ pass 2
ℹ fail 0
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 6.242459
ℹ start of coverage report
ℹ ---------------------------------------------------------------
ℹ file | line % | branch % | funcs % | uncovered lines
ℹ ---------------------------------------------------------------
ℹ index.test.mjs | 100.00 | 100.00 | 100.00 |
ℹ sub/index.mjs | 100.00 | 100.00 | 100.00 |
ℹ sum/index.mjs | 100.00 | 100.00 | 100.00 |
ℹ ---------------------------------------------------------------
ℹ all files | 100.00 | 100.00 | 100.00 |
ℹ ---------------------------------------------------------------
ℹ minimum coverage failed for line. expected: 101 | actual: 100
ℹ minimum coverage failed for function. expected: 101 | actual: 100
ℹ minimum coverage failed for branch. expected: 101 | actual: 100
ℹ end of coverage report|
It’s still missing “statements”. |
I think we don't collect statement coverage summary. @MoLow please confirm about statement summary here and how can we support that. |
| @@ -500,3 +500,42 @@ describe('require(\'node:test\').run', { concurrency: true }, () => { | |||
| for await (const _ of stream); | |||
| }); | |||
| }); | |||
|
|
|||
| describe('coverage report for test stream', () => { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have 3 tests here with the same name, please rename
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my bad 😞.
fixed now 🚀


fixes #48739
Added support for coverage threshold comparison.
example:
code:
output:
cmd:
./node --experimental-test-coverage=110 index.mjscode:
output: