Skip to content

Commit

Permalink
test_runner: give the root test a harness reference
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cjihrig authored and danielleadams committed Apr 11, 2023
1 parent 5b94e2b commit 15503ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 6 additions & 1 deletion lib/internal/test_runner/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 15503ff

Please sign in to comment.