Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 882c612

Browse filesBrowse files
cjihrigMoLow
authored andcommitted
test_runner: move coverage collection to root.postRun()
This commit moves code coverage collection from the test harness exit handler to the postRun() function of the root test. This is necessary preparatory work for supporting code coverage with --test. The reason is that --test is implemented on top of run(), and that function calls the root test's postRun() function, which outputs the test summary. This happens before the harness exit handler. PR-URL: #47651 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 6535ab9 commit 882c612
Copy full SHA for 882c612

File tree

Expand file treeCollapse file tree

2 files changed

+6
-4
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+6
-4
lines changed
Open diff view settings
Collapse file

‎lib/internal/test_runner/harness.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/harness.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
const {
33
ArrayPrototypeForEach,
4+
FunctionPrototypeBind,
45
PromiseResolve,
56
SafeMap,
67
} = primordials;
@@ -138,7 +139,6 @@ function setup(root) {
138139
createProcessEventHandler('unhandledRejection', root);
139140
const coverage = configureCoverage(root, globalOptions);
140141
const exitHandler = () => {
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));
@@ -165,7 +165,7 @@ function setup(root) {
165165
root.harness = {
166166
__proto__: null,
167167
bootstrapComplete: false,
168-
coverage: null,
168+
coverage: FunctionPrototypeBind(collectCoverage, null, root, coverage),
169169
counters: {
170170
__proto__: null,
171171
all: 0,
Collapse file

‎lib/internal/test_runner/test.js‎

Copy file name to clipboardExpand all lines: lib/internal/test_runner/test.js
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,10 @@ class Test extends AsyncResource {
644644
this.reporter.diagnostic(this.nesting, kFilename, `todo ${this.root.harness.counters.todo}`);
645645
this.reporter.diagnostic(this.nesting, kFilename, `duration_ms ${this.#duration()}`);
646646

647-
if (this.harness?.coverage) {
648-
this.reporter.coverage(this.nesting, kFilename, this.harness.coverage);
647+
const coverage = this.harness.coverage();
648+
649+
if (coverage) {
650+
this.reporter.coverage(this.nesting, kFilename, coverage);
649651
}
650652

651653
this.reporter.push(null);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.