Skip to content

Commit

Permalink
debugger: improve code coverage for errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cola119 committed Mar 12, 2022
1 parent b35ee26 commit 7fe0f4c
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 7fe0f4c

Please sign in to comment.