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

test: improve code coverage for inspector connection errors #42310

Merged
merged 1 commit into from
May 25, 2022
Merged
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
29 changes: 25 additions & 4 deletions test/parallel/test-inspector-connect-main-thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { Session } = require('inspector');
const path = require('path');
const { pathToFileURL } = require('url');
const { isMainThread, parentPort, Worker, workerData } =
require('worker_threads');
require('worker_threads');

if (!workerData) {
common.skipIfWorker();
Expand Down Expand Up @@ -100,6 +100,17 @@ async function ensureListenerDoesNotInterrupt(session) {
}

async function main() {
assert.throws(
() => {
const session = new Session();
session.connectToMainThread();
},
{
code: 'ERR_INSPECTOR_NOT_WORKER',
name: 'Error',
message: 'Current thread is not a worker'
}
);
const sharedBuffer = new SharedArrayBuffer(1);
const arrayBuffer = new Uint8Array(sharedBuffer);
arrayBuffer[0] = 1;
Expand All @@ -121,6 +132,16 @@ async function childMain() {
await (await startWorker(true)).onMessagesSent;
const session = new Session();
session.connectToMainThread();
assert.throws(
() => {
session.connectToMainThread();
},
{
code: 'ERR_INSPECTOR_ALREADY_CONNECTED',
name: 'Error',
message: 'The inspector session is already connected'
}
);
await post(session, 'Debugger.enable');
await post(session, 'Runtime.enable');
await post(session, 'Debugger.setBreakpointByUrl', {
Expand All @@ -137,9 +158,9 @@ async function childMain() {
await new Promise((resolve) => setTimeout(resolve, 50));

const { result: { value } } =
await post(session,
'Debugger.evaluateOnCallFrame',
{ callFrameId, expression: 'a * 100' });
await post(session,
'Debugger.evaluateOnCallFrame',
{ callFrameId, expression: 'a * 100' });
assert.strictEqual(value, 100);
await post(session, 'Debugger.resume');
await ensureListenerDoesNotInterrupt(session);
Expand Down