Skip to content

Commit 162bf0d

Browse files
MoLowRafaelGSS
authored andcommittedNov 10, 2022
src: fix test runner coverage
PR-URL: #45055 Fixes: #45013 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 17e86e4 commit 162bf0d

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
@@ -679,9 +679,6 @@ bool Agent::Start(const std::string& path,
679679
const DebugOptions& options,
680680
std::shared_ptr<ExclusiveAccess<HostPort>> host_port,
681681
bool is_main) {
682-
if (!options.allow_attaching_debugger) {
683-
return false;
684-
}
685682
path_ = path;
686683
debug_options_ = options;
687684
CHECK_NOT_NULL(host_port);
@@ -725,7 +722,8 @@ bool Agent::Start(const std::string& path,
725722
if (parent_handle_) {
726723
wait_for_connect = parent_handle_->WaitForConnect();
727724
parent_handle_->WorkerStarted(client_->getThreadHandle(), wait_for_connect);
728-
} else if (!options.inspector_enabled || !StartIoThread()) {
725+
} else if (!options.inspector_enabled || !options.allow_attaching_debugger ||
726+
!StartIoThread()) {
729727
return false;
730728
}
731729

@@ -920,6 +918,9 @@ void Agent::RequestIoThreadStart() {
920918
// We need to attempt to interrupt V8 flow (in case Node is running
921919
// continuous JS code) and to wake up libuv thread (in case Node is waiting
922920
// for IO events)
921+
if (!options().allow_attaching_debugger) {
922+
return;
923+
}
923924
CHECK(start_io_thread_async_initialized);
924925
uv_async_send(&start_io_thread_async);
925926
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)
Please sign in to comment.