Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
islandryu committed Feb 3, 2025
1 parent 234a139 commit 01011f6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
3 changes: 3 additions & 0 deletions test/fixtures/inspect-worker/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const { Worker } = require('worker_threads');

new Worker(__dirname + '/worker.js', { type: 'module' });
4 changes: 4 additions & 0 deletions test/fixtures/inspect-worker/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
console.log("worker thread");
process.on('exit', () => {
console.log('Worker1: Exiting...');
});
55 changes: 39 additions & 16 deletions test/parallel/test-inspector-worker-target.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
// Flags: --inspect=0 --experimental-worker-inspection
'use strict';

const common = require('../common');
const fixtures = require('../common/fixtures');
const { Worker } = require('worker_threads');

common.skipIfInspectorDisabled();

const assert = require('assert');
const { Session } = require('inspector');
const { NodeInstance } = require('../common/inspector-helper.js');

const session = new Session();
(async () => {
const child = new NodeInstance(['--inspect-brk', '--experimental-worker-inspection'],
'',
fixtures.path('inspect-worker/index.js')
);

session.connect();
const session = await child.connectInspectorSession();
await session.send({ method: 'NodeRuntime.enable' });
await session.waitForNotification('NodeRuntime.waitingForDebugger');
await session.send({ method: 'Runtime.enable' });
await session.send({ method: 'Debugger.enable' });
await session.send({ method: 'Runtime.runIfWaitingForDebugger' });
await session.send({ method: 'NodeRuntime.disable' });
await session.waitForNotification((notification) => {
// // The main assertion here is that we do hit the loader script first.
return notification.method === 'Debugger.scriptParsed' &&
notification.params.url === 'node:internal/bootstrap/realm';
});

new Worker(fixtures.path('worker-script.mjs'), { type: 'module' });
session.on('Target.targetCreated', common.mustCall(({ params }) => {
const targetInfo = params.targetInfo;
assert.strictEqual(targetInfo.type, 'worker');
assert.ok(targetInfo.url.includes('worker-script.mjs'));
assert.strictEqual(targetInfo.targetId, '1');
}));
await session.waitForNotification('Debugger.paused');
await session.send({ method: 'Debugger.resume' });

session.on('Target.attachedToTarget', common.mustCall(({ params }) => {
assert.strictEqual(params.sessionId, '1');
}));
const sessionId = '1';
await session.waitForNotification('Target.targetCreated');
await session.waitForNotification((notification) => {
return notification.method === 'Target.attachedToTarget' &&
notification.params.sessionId === sessionId;
});

await session.send({ method: 'Runtime.enable', sessionId });
await session.send({ method: 'Debugger.enable', sessionId });
await session.send({ method: 'Runtime.runIfWaitingForDebugger', sessionId });
await session.send({ method: 'NodeRuntime.enable', sessionId });
await session.waitForNotification((notification) => {
return notification.method === 'Debugger.scriptParsed' &&
notification.params.url === 'node:internal/bootstrap/realm';
});
await session.waitForNotification('Debugger.paused');
await session.send({ method: 'Debugger.resume', sessionId });
await session.waitForDisconnect();
})().then(common.mustCall());

0 comments on commit 01011f6

Please sign in to comment.