Skip to content

Commit b191f09

Browse files
committed
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 <moshe@atlow.co.il> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent b164038 commit b191f09

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/internal/test_runner/harness.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function setup(root) {
139139
createProcessEventHandler('unhandledRejection', root);
140140
const coverage = configureCoverage(root, globalOptions);
141141
const exitHandler = () => {
142-
root.coverage = collectCoverage(root, coverage);
142+
root.harness.coverage = collectCoverage(root, coverage);
143143
root.postRun(new ERR_TEST_FAILURE(
144144
'Promise resolution is still pending but the event loop has already resolved',
145145
kCancelledByParent));
@@ -163,6 +163,11 @@ function setup(root) {
163163
process.on('SIGTERM', terminationHandler);
164164
}
165165

166+
root.harness = {
167+
__proto__: null,
168+
bootstrapComplete: false,
169+
coverage: null,
170+
};
166171
root.startTime = hrtime();
167172

168173
wasRootSetup.add(root);

lib/internal/test_runner/test.js

Lines changed: 3 additions & 3 deletions
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)