-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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 support with watch mode #51288
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Review requested:
|
atlowChemi
reviewed
Dec 26, 2023
MoLow
reviewed
Dec 26, 2023
I propose this implementation, which is a little simpler: diff --git a/lib/internal/test_runner/harness.js b/lib/internal/test_runner/harness.js
index 2f18b0bcf0..29dc7ca495 100644
--- a/lib/internal/test_runner/harness.js
+++ b/lib/internal/test_runner/harness.js
@@ -177,6 +177,7 @@ function setup(root) {
root.harness = {
__proto__: null,
bootstrapComplete: false,
+ watchMode: false,
coverage: FunctionPrototypeBind(collectCoverage, null, root, coverage),
counters: {
__proto__: null,
diff --git a/lib/internal/test_runner/runner.js b/lib/internal/test_runner/runner.js
index c4194923cc..810a3ee13e 100644
--- a/lib/internal/test_runner/runner.js
+++ b/lib/internal/test_runner/runner.js
@@ -78,7 +78,7 @@ const {
exitCodes: { kGenericUserError },
} = internalBinding('errors');
-const kFilterArgs = ['--test', '--experimental-test-coverage', '--watch'];
+const kFilterArgs = new SafeSet(['--test', '--experimental-test-coverage', '--watch']);
const kFilterArgValues = ['--test-reporter', '--test-reporter-destination'];
const kDiagnosticsFilterArgs = ['tests', 'suites', 'pass', 'fail', 'cancelled', 'skipped', 'todo', 'duration_ms'];
@@ -107,7 +107,7 @@ function createTestFileList() {
}
function filterExecArgv(arg, i, arr) {
- return !ArrayPrototypeIncludes(kFilterArgs, arg) &&
+ return !kFilterArgs.has(arg) &&
!ArrayPrototypeSome(kFilterArgValues, (p) => arg === p || (i > 0 && arr[i - 1] === p) || StringPrototypeStartsWith(arg, `${p}=`));
}
@@ -425,11 +425,10 @@ function watchFiles(testFiles, opts) {
});
if (opts.signal) {
kResistStopPropagation ??= require('internal/event_target').kResistStopPropagation;
- opts.signal.addEventListener(
- 'abort',
- () => opts.root.postRun(),
- { __proto__: null, once: true, [kResistStopPropagation]: true },
- );
+ opts.signal.addEventListener('abort', () => {
+ opts.root.postRun();
+ opts.root.reporter.end();
+ }, { __proto__: null, once: true, [kResistStopPropagation]: true });
}
return filesWatcher;
@@ -497,8 +496,12 @@ function run(options = kEmptyObject) {
let filesWatcher;
const opts = { __proto__: null, root, signal, inspectPort, testNamePatterns, only };
if (watch) {
+ root.harness.watchMode = true;
filesWatcher = watchFiles(testFiles, opts);
- postRun = undefined;
+ postRun = () => {
+ kFilterArgs.delete('--experimental-test-coverage');
+ root.postRun();
+ };
}
const runFiles = () => {
root.harness.bootstrapComplete = true;
diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js
index 4eb02c5d4e..b28d00dce2 100644
--- a/lib/internal/test_runner/test.js
+++ b/lib/internal/test_runner/test.js
@@ -756,7 +756,9 @@ class Test extends AsyncResource {
reporter.coverage(nesting, loc, coverage);
}
- reporter.end();
+ if (harness.watchMode === false) {
+ reporter.end();
+ }
}
} |
yeah looks clean 👍🏼 |
MoLow
approved these changes
Jan 2, 2024
benjamingr
approved these changes
Jan 2, 2024
rluvaton
reviewed
Jan 2, 2024
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.
Left some comments, great job
atlowChemi
reviewed
Jan 5, 2024
atlowChemi
approved these changes
Jan 7, 2024
@pulkit-30 the failure is related to the changes: not ok 2474 parallel/test-runner-watch-coverage
---
duration_ms: 2215.81000
severity: fail
exitcode: 1
stack: |-
TAP version 13
# Subtest: test runner must report coverage report with watch mode
# Subtest: should report coverage report with watch mode
not ok 1 - should report coverage report with watch mode
---
duration_ms: 1797.885443
location: 'file:///home/iojs/build/workspace/node-test-commit-linux-containered/test/parallel/test-runner-watch-coverage.mjs:80:3'
failureType: 'testCodeFailure'
error: |-
The expression evaluated to a falsy value:
assert(stdout.includes(getCoverageFixtureReport('tap')))
code: 'ERR_ASSERTION'
name: 'AssertionError'
expected: true
actual: false
operator: '=='
stack: |-
TestContext.<anonymous> (file:///home/iojs/build/workspace/node-test-commit-linux-containered/test/parallel/test-runner-watch-coverage.mjs:82:5)
process.processTicksAndRejections (node:internal/process/task_queues:95:5)
async Test.run (node:internal/test_runner/test:632:9)
async Promise.all (index 0)
async Suite.run (node:internal/test_runner/test:951:7)
async startSubtest (node:internal/test_runner/harness:219:3)
...
1..1
not ok 1 - test runner must report coverage report with watch mode
---
duration_ms: 1801.223591
type: 'suite'
location: 'file:///home/iojs/build/workspace/node-test-commit-linux-containered/test/parallel/test-runner-watch-coverage.mjs:79:1'
failureType: 'subtestsFailed'
error: '1 subtest failed'
code: 'ERR_TEST_FAILURE'
...
1..1
# tests 1
# suites 1
# pass 0
# fail 1
# cancelled 0
# skipped 0
# todo 0
# duration_ms 1826.192055
... |
atlowChemi
approved these changes
Jan 8, 2024
The linked issue is now closed, so I'll go ahead and close this as well. Thanks for the PR though. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
author ready
PRs that have at least one approval, no pending requests for changes, and a CI started.
needs-ci
PRs that need a full CI run.
test_runner
Issues and PRs related to the test runner subsystem.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix #51253
code:
with following test files
run
node --test --experimental-test-coverage --watch
output:
test2.test.mjs