Skip to content

Commit

Permalink
src: fix test runner coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Oct 18, 2022
1 parent 7ceb624 commit 1f7f85e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
7 changes: 3 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,9 @@ 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
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 1f7f85e

Please sign in to comment.