diff --git a/lib/internal/test_runner/harness.js b/lib/internal/test_runner/harness.js index 7ffe1a4fb70b11..75931ff1155039 100644 --- a/lib/internal/test_runner/harness.js +++ b/lib/internal/test_runner/harness.js @@ -138,7 +138,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)); @@ -162,6 +162,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 0ccfd96605a939..254a0fcae0f478 100644 --- a/lib/internal/test_runner/test.js +++ b/lib/internal/test_runner/test.js @@ -251,7 +251,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; @@ -637,8 +637,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);