Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: fix test runner coverage #45055

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/inspector_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -679,9 +679,6 @@ bool Agent::Start(const std::string& path,
const DebugOptions& options,
std::shared_ptr<ExclusiveAccess<HostPort>> host_port,
bool is_main) {
if (!options.allow_attaching_debugger) {
return false;
}
path_ = path;
debug_options_ = options;
CHECK_NOT_NULL(host_port);
Expand Down Expand Up @@ -725,7 +722,8 @@ bool Agent::Start(const std::string& path,
if (parent_handle_) {
wait_for_connect = parent_handle_->WaitForConnect();
parent_handle_->WorkerStarted(client_->getThreadHandle(), wait_for_connect);
} else if (!options.inspector_enabled || !StartIoThread()) {
} else if (!options.inspector_enabled || !options.allow_attaching_debugger ||
!StartIoThread()) {
return false;
}

Expand Down Expand Up @@ -920,6 +918,9 @@ void Agent::RequestIoThreadStart() {
// We need to attempt to interrupt V8 flow (in case Node is running
// continuous JS code) and to wake up libuv thread (in case Node is waiting
// for IO events)
if (!options().allow_attaching_debugger) {
return;
}
CHECK(start_io_thread_async_initialized);
uv_async_send(&start_io_thread_async);
parent_env_->RequestInterrupt([this](Environment*) {
Expand Down
30 changes: 30 additions & 0 deletions test/parallel/test-runner-inspect.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as common from '../common/index.mjs';
import * as tmpdir from '../common/tmpdir.js';
import * as fixtures from '../common/fixtures.mjs';
import assert from 'node:assert';
import path from 'node:path';
import fs from 'node:fs/promises';
import { NodeInstance } from '../common/inspector-helper.js';


Expand Down Expand Up @@ -52,3 +54,31 @@ tmpdir.refresh();
assert.strictEqual(code, 1);
assert.strictEqual(signal, null);
}


// Outputs coverage when event loop is drained, with no async logic.
{
const coverageDirectory = path.join(tmpdir.path, 'coverage');
async function getCoveredFiles() {
const coverageFiles = await fs.readdir(coverageDirectory);
const files = new Set();
for (const coverageFile of coverageFiles) {
const coverage = JSON.parse(await fs.readFile(path.join(coverageDirectory, coverageFile)));
for (const { url } of coverage.result) {
if (!url.startsWith('node:')) files.add(url);
}
}
return files;
}

const { stderr, code, signal } = await common
.spawnPromisified(process.execPath,
['--test', fixtures.path('v8-coverage/basic.js')],
{ env: { ...process.env, NODE_V8_COVERAGE: coverageDirectory } });

assert.strictEqual(stderr, '');
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
const files = await getCoveredFiles(coverageDirectory);
assert.ok(files.has(fixtures.fileURL('v8-coverage/basic.js').href));
}