Skip to content

Commit 3e1ed1e

Browse files
cola119bengl
authored andcommitted
test: improve code coverage for inspector connection errors
PR-URL: #42310 Refs: https://coverage.nodejs.org/coverage-457567f72ca73ef0/lib/inspector.js.html#L74 Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 87b248e commit 3e1ed1e

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

‎test/parallel/test-inspector-connect-main-thread.js‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const{Session } = require('inspector');
88
constpath=require('path');
99
const{ pathToFileURL }=require('url');
1010
const{ isMainThread, parentPort, Worker, workerData }=
11-
require('worker_threads');
11+
require('worker_threads');
1212

1313
if(!workerData){
1414
common.skipIfWorker();
@@ -100,6 +100,17 @@ async function ensureListenerDoesNotInterrupt(session){
100100
}
101101

102102
asyncfunctionmain(){
103+
assert.throws(
104+
()=>{
105+
constsession=newSession();
106+
session.connectToMainThread();
107+
},
108+
{
109+
code: 'ERR_INSPECTOR_NOT_WORKER',
110+
name: 'Error',
111+
message: 'Current thread is not a worker'
112+
}
113+
);
103114
constsharedBuffer=newSharedArrayBuffer(1);
104115
constarrayBuffer=newUint8Array(sharedBuffer);
105116
arrayBuffer[0]=1;
@@ -121,6 +132,16 @@ async function childMain(){
121132
await(awaitstartWorker(true)).onMessagesSent;
122133
constsession=newSession();
123134
session.connectToMainThread();
135+
assert.throws(
136+
()=>{
137+
session.connectToMainThread();
138+
},
139+
{
140+
code: 'ERR_INSPECTOR_ALREADY_CONNECTED',
141+
name: 'Error',
142+
message: 'The inspector session is already connected'
143+
}
144+
);
124145
awaitpost(session,'Debugger.enable');
125146
awaitpost(session,'Runtime.enable');
126147
awaitpost(session,'Debugger.setBreakpointByUrl',{
@@ -137,9 +158,9 @@ async function childMain(){
137158
awaitnewPromise((resolve)=>setTimeout(resolve,50));
138159

139160
const{result: { value }}=
140-
awaitpost(session,
141-
'Debugger.evaluateOnCallFrame',
142-
{ callFrameId,expression: 'a * 100'});
161+
awaitpost(session,
162+
'Debugger.evaluateOnCallFrame',
163+
{ callFrameId,expression: 'a * 100'});
143164
assert.strictEqual(value,100);
144165
awaitpost(session,'Debugger.resume');
145166
awaitensureListenerDoesNotInterrupt(session);

0 commit comments

Comments
(0)