Skip to content

Commit

Permalink
src: fix test runner coverage
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
MoLow authored and RafaelGSS committed Nov 10, 2022
1 parent 17e86e4 commit 162bf0d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
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));
}

0 comments on commit 162bf0d

Please sign in to comment.