Skip to content

Commit 15503ff

Browse files
cjihrigdanielleadams
authored andcommitted
test_runner: give the root test a harness reference
This commit replaces the 'coverage' reference inside of the Test class with a more generic harness reference which includes coverage. This will let the root test more easily track process level state such as code coverage, uncaughtException handlers, and the state of bootstrapping. PR-URL: #46962 Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
1 parent 5b94e2b commit 15503ff

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/internal/test_runner/harness.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ function setup(root) {
136136
createProcessEventHandler('unhandledRejection', root);
137137
const coverage = configureCoverage(root, globalOptions);
138138
const exitHandler = () => {
139-
root.coverage = collectCoverage(root, coverage);
139+
root.harness.coverage = collectCoverage(root, coverage);
140140
root.postRun(new ERR_TEST_FAILURE(
141141
'Promise resolution is still pending but the event loop has already resolved',
142142
kCancelledByParent));
@@ -160,6 +160,11 @@ function setup(root) {
160160
process.on('SIGTERM', terminationHandler);
161161
}
162162

163+
root.harness = {
164+
__proto__: null,
165+
bootstrapComplete: false,
166+
coverage: null,
167+
};
163168
root.startTime = hrtime();
164169

165170
wasRootSetup.add(root);

lib/internal/test_runner/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ class Test extends AsyncResource {
252252
this.#outerSignal?.addEventListener('abort', this.#abortHandler);
253253

254254
this.fn = fn;
255-
this.coverage = null; // Configured on the root test by the test harness.
255+
this.harness = null; // Configured on the root test by the test harness.
256256
this.mock = null;
257257
this.name = name;
258258
this.parent = parent;
@@ -651,8 +651,8 @@ class Test extends AsyncResource {
651651
this.reporter.diagnostic(this.nesting, kFilename, `todo ${counters.todo}`);
652652
this.reporter.diagnostic(this.nesting, kFilename, `duration_ms ${this.#duration()}`);
653653

654-
if (this.coverage) {
655-
this.reporter.coverage(this.nesting, kFilename, this.coverage);
654+
if (this.harness?.coverage) {
655+
this.reporter.coverage(this.nesting, kFilename, this.harness.coverage);
656656
}
657657

658658
this.reporter.push(null);

0 commit comments

Comments
 (0)