Skip to content

Commit

Permalink
test: improve code coverage for inspector connection errors
Browse files Browse the repository at this point in the history
PR-URL: #42310
Refs: https://coverage.nodejs.org/coverage-457567f72ca73ef0/lib/inspector.js.html#L74
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
  • Loading branch information
cola119 authored and bengl committed May 30, 2022
1 parent 87b248e commit 3e1ed1e
Showing 1 changed file with 25 additions and 4 deletions.
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

0 comments on commit 3e1ed1e

Please sign in to comment.