summaryrefslogtreecommitdiff
path: root/lib/internal
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2023-04-23 02:57:10 -0400
committerGitHub <noreply@github.com>2023-04-23 06:57:10 +0000
commitecb023be8a27abf350188be918860a00a7fa8aab (patch)
treec44fd03a9a183242d70f81c437e9066d838ca80e /lib/internal
parentdb1bf9ddbb1e400fef7465d107db3f919abece4d (diff)
downloadnode-new-ecb023be8a27abf350188be918860a00a7fa8aab.tar.gz
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: https://github.com/nodejs/node/pull/47651 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Diffstat (limited to 'lib/internal')
-rw-r--r--lib/internal/test_runner/harness.js4
-rw-r--r--lib/internal/test_runner/test.js6
2 files changed, 6 insertions, 4 deletions
diff --git a/lib/internal/test_runner/harness.js b/lib/internal/test_runner/harness.js
index 95a8c5f869..7457ca62ef 100644
--- a/lib/internal/test_runner/harness.js
+++ b/lib/internal/test_runner/harness.js
@@ -1,6 +1,7 @@
'use strict';
const {
ArrayPrototypeForEach,
+ FunctionPrototypeBind,
PromiseResolve,
SafeMap,
} = primordials;
@@ -140,7 +141,6 @@ function setup(root) {
createProcessEventHandler('unhandledRejection', root);
const coverage = configureCoverage(root, globalOptions);
const exitHandler = () => {
- 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));
@@ -167,7 +167,7 @@ function setup(root) {
root.harness = {
__proto__: null,
bootstrapComplete: false,
- coverage: null,
+ coverage: FunctionPrototypeBind(collectCoverage, null, root, coverage),
counters: {
__proto__: null,
all: 0,
diff --git a/lib/internal/test_runner/test.js b/lib/internal/test_runner/test.js
index c5ceda91dd..59125a6574 100644
--- a/lib/internal/test_runner/test.js
+++ b/lib/internal/test_runner/test.js
@@ -644,8 +644,10 @@ class Test extends AsyncResource {
this.reporter.diagnostic(this.nesting, kFilename, `todo ${this.root.harness.counters.todo}`);
this.reporter.diagnostic(this.nesting, kFilename, `duration_ms ${this.#duration()}`);
- if (this.harness?.coverage) {
- this.reporter.coverage(this.nesting, kFilename, this.harness.coverage);
+ const coverage = this.harness.coverage();
+
+ if (coverage) {
+ this.reporter.coverage(this.nesting, kFilename, coverage);
}
this.reporter.push(null);