Skip to content

Commit 57b7023

Browse files
MoLowdanielleadams
authored andcommitted
src: fix test runner coverage
PR-URL: #45055 Fixes: #45013 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 52808d7 commit 57b7023

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/inspector_agent.cc

+5-4
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,6 @@ bool Agent::Start(const std::string& path,
676676
const DebugOptions& options,
677677
std::shared_ptr<ExclusiveAccess<HostPort>> host_port,
678678
bool is_main) {
679-
if (!options.allow_attaching_debugger) {
680-
return false;
681-
}
682679
path_ = path;
683680
debug_options_ = options;
684681
CHECK_NOT_NULL(host_port);
@@ -722,7 +719,8 @@ bool Agent::Start(const std::string& path,
722719
if (parent_handle_) {
723720
wait_for_connect = parent_handle_->WaitForConnect();
724721
parent_handle_->WorkerStarted(client_->getThreadHandle(), wait_for_connect);
725-
} else if (!options.inspector_enabled || !StartIoThread()) {
722+
} else if (!options.inspector_enabled || !options.allow_attaching_debugger ||
723+
!StartIoThread()) {
726724
return false;
727725
}
728726

@@ -917,6 +915,9 @@ void Agent::RequestIoThreadStart() {
917915
// We need to attempt to interrupt V8 flow (in case Node is running
918916
// continuous JS code) and to wake up libuv thread (in case Node is waiting
919917
// for IO events)
918+
if (!options().allow_attaching_debugger) {
919+
return;
920+
}
920921
CHECK(start_io_thread_async_initialized);
921922
uv_async_send(&start_io_thread_async);
922923
parent_env_->RequestInterrupt([this](Environment*) {

test/parallel/test-runner-inspect.mjs

+30
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import * as common from '../common/index.mjs';
22
import * as tmpdir from '../common/tmpdir.js';
33
import * as fixtures from '../common/fixtures.mjs';
44
import assert from 'node:assert';
5+
import path from 'node:path';
6+
import fs from 'node:fs/promises';
57
import { NodeInstance } from '../common/inspector-helper.js';
68

79

@@ -52,3 +54,31 @@ tmpdir.refresh();
5254
assert.strictEqual(code, 1);
5355
assert.strictEqual(signal, null);
5456
}
57+
58+
59+
// Outputs coverage when event loop is drained, with no async logic.
60+
{
61+
const coverageDirectory = path.join(tmpdir.path, 'coverage');
62+
async function getCoveredFiles() {
63+
const coverageFiles = await fs.readdir(coverageDirectory);
64+
const files = new Set();
65+
for (const coverageFile of coverageFiles) {
66+
const coverage = JSON.parse(await fs.readFile(path.join(coverageDirectory, coverageFile)));
67+
for (const { url } of coverage.result) {
68+
if (!url.startsWith('node:')) files.add(url);
69+
}
70+
}
71+
return files;
72+
}
73+
74+
const { stderr, code, signal } = await common
75+
.spawnPromisified(process.execPath,
76+
['--test', fixtures.path('v8-coverage/basic.js')],
77+
{ env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } });
78+
79+
assert.strictEqual(stderr, '');
80+
assert.strictEqual(code, 0);
81+
assert.strictEqual(signal, null);
82+
const files = await getCoveredFiles(coverageDirectory);
83+
assert.ok(files.has(fixtures.fileURL('v8-coverage/basic.js').href));
84+
}

0 commit comments

Comments
 (0)