From ba42c4c3d57822649215905dcf089ee525dbd3a8 Mon Sep 17 00:00:00 2001 From: cola119 Date: Sun, 13 Mar 2022 12:30:16 +0900 Subject: [PATCH] test: improve code coverage for inspector connection errors --- .../test-inspector-connect-main-thread.js | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-inspector-connect-main-thread.js b/test/parallel/test-inspector-connect-main-thread.js index 86ff6866bc064e..b724bf3cd9d62f 100644 --- a/test/parallel/test-inspector-connect-main-thread.js +++ b/test/parallel/test-inspector-connect-main-thread.js @@ -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(); @@ -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; @@ -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', { @@ -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);