diff --git a/lib/internal/test_runner/harness.js b/lib/internal/test_runner/harness.js index be57f92268355c..95715769a3632f 100644 --- a/lib/internal/test_runner/harness.js +++ b/lib/internal/test_runner/harness.js @@ -136,7 +136,7 @@ function setup(root) { createProcessEventHandler('unhandledRejection', root); const coverage = configureCoverage(root, globalOptions); const exitHandler = () => { - root.coverage = collectCoverage(root, coverage); + root.harness.coverage = collectCoverage(root, coverage); root.postRun(new ERR_TEST_FAILURE( 'Promise resolution is still pending but the event loop has already resolved', kCancelledByParent)); @@ -160,6 +160,11 @@ function setup(root) { process.on('SIGTERM', terminationHandler); } + root.harness = { + __proto__: null, + bootstrapComplete: false, + coverage: null, + }; root.startTime = hrtime(); wasRootSetup.add(root); diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js index 77516a93c00df8..f6a71002803699 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -252,7 +252,7 @@ class Test extends AsyncResource { this.#outerSignal?.addEventListener('abort', this.#abortHandler); this.fn = fn; - this.coverage = null; // Configured on the root test by the test harness. + this.harness = null; // Configured on the root test by the test harness. this.mock = null; this.name = name; this.parent = parent; @@ -651,8 +651,8 @@ class Test extends AsyncResource { this.reporter.diagnostic(this.nesting, kFilename, `todo ${counters.todo}`); this.reporter.diagnostic(this.nesting, kFilename, `duration_ms ${this.#duration()}`); - if (this.coverage) { - this.reporter.coverage(this.nesting, kFilename, this.coverage); + if (this.harness?.coverage) { + this.reporter.coverage(this.nesting, kFilename, this.harness.coverage); } this.reporter.push(null);