Skip to content

Commit 4b7198c

Browse files
cjihrigtargos
authored andcommittedMar 14, 2023
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 9d4d916 commit 4b7198c

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
@@ -138,7 +138,7 @@ function setup(root) {
138138
createProcessEventHandler('unhandledRejection', root);
139139
const coverage = configureCoverage(root, globalOptions);
140140
const exitHandler = () => {
141-
root.coverage = collectCoverage(root, coverage);
141+
root.harness.coverage = collectCoverage(root, coverage);
142142
root.postRun(new ERR_TEST_FAILURE(
143143
'Promise resolution is still pending but the event loop has already resolved',
144144
kCancelledByParent));
@@ -162,6 +162,11 @@ function setup(root) {
162162
process.on('SIGTERM', terminationHandler);
163163
}
164164

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

167172
wasRootSetup.add(root);

‎lib/internal/test_runner/test.js

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

253253
this.fn = fn;
254-
this.coverage = null; // Configured on the root test by the test harness.
254+
this.harness = null; // Configured on the root test by the test harness.
255255
this.mock = null;
256256
this.name = name;
257257
this.parent = parent;
@@ -637,8 +637,8 @@ class Test extends AsyncResource {
637637
this.reporter.diagnostic(this.nesting, kFilename, `todo ${counters.todo}`);
638638
this.reporter.diagnostic(this.nesting, kFilename, `duration_ms ${this.#duration()}`);
639639

640-
if (this.coverage) {
641-
this.reporter.coverage(this.nesting, kFilename, this.coverage);
640+
if (this.harness?.coverage) {
641+
this.reporter.coverage(this.nesting, kFilename, this.harness.coverage);
642642
}
643643

644644
this.reporter.push(null);

0 commit comments

Comments
 (0)