forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-inspector-worker-target.js
More file actions
90 lines (75 loc) · 3.6 KB
/
test-inspector-worker-target.js
File metadata and controls
90 lines (75 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
'use strict';
const common = require('../common');
const fixtures = require('../common/fixtures');
const assert = require('assert');
common.skipIfInspectorDisabled();
const { NodeInstance } = require('../common/inspector-helper.js');
async function setupInspector(session, sessionId = undefined) {
await session.send({ method: 'NodeRuntime.enable', sessionId });
await session.waitForNotification('NodeRuntime.waitingForDebugger');
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.disable', sessionId });
await session.waitForNotification((notification) => {
return notification.method === 'Debugger.scriptParsed' &&
notification.params.url === 'node:internal/bootstrap/realm' &&
notification.sessionId === sessionId;
});
}
async function assertTargetAttachedState(session, targetId, attached) {
const { targetInfos } = await session.send({ method: 'Target.getTargets' });
const targetInfo = targetInfos.find((target) => {
return target.targetId === targetId;
});
assert.notStrictEqual(targetInfo, undefined);
assert.strictEqual(targetInfo.attached, attached);
}
async function test(isSetAutoAttachBeforeExecution) {
const child = new NodeInstance(['--inspect-brk=0', '--experimental-worker-inspection'],
'',
fixtures.path('inspect-worker/index.js')
);
const session = await child.connectInspectorSession();
await setupInspector(session);
if (isSetAutoAttachBeforeExecution) {
await session.send({ method: 'Target.setAutoAttach', params: { autoAttach: true, waitForDebuggerOnStart: true } });
}
await session.waitForNotification('Debugger.paused');
await session.send({ method: 'Debugger.resume' });
const sessionId = '1';
const targetCreated = await session.waitForNotification('Target.targetCreated');
const targetId = targetCreated.params.targetInfo.targetId;
await assertTargetAttachedState(session, targetId, isSetAutoAttachBeforeExecution);
if (!isSetAutoAttachBeforeExecution) {
await session.send({ method: 'Target.setAutoAttach', params: { autoAttach: true, waitForDebuggerOnStart: true } });
}
await session.waitForNotification((notification) => {
return notification.method === 'Target.attachedToTarget' &&
notification.params.sessionId === sessionId;
});
await assertTargetAttachedState(session, targetId, true);
await setupInspector(session, sessionId);
await session.waitForNotification('Debugger.paused');
await session.send({ method: 'Debugger.resume', sessionId });
await session.waitForDisconnect();
}
test(true).then(common.mustCall());
test(false).then(common.mustCall());
function withPermissionOptionTest() {
const permissionErrorThrow = common.mustCall();
const child = new NodeInstance(['--inspect-brk=0', '--experimental-worker-inspection', '--permission'],
'',
fixtures.path('inspect-worker/index.js'),
{
log: (_, msg) => {
if (msg.includes('Access to this API has been restricted')) {
permissionErrorThrow();
}
},
error: () => {},
}
);
child.connectInspectorSession();
}
withPermissionOptionTest();