forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-inspector-contexts.js
56 lines (48 loc) · 1.4 KB
/
test-inspector-contexts.js
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
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const assert = require('assert');
const helper = require('./inspector-helper.js');
function setupExpectBreakInContext() {
return function(message) {
if ('Debugger.paused' === message['method']) {
const callFrame = message['params']['callFrames'][0];
assert.strictEqual(callFrame['functionName'], 'testfn');
return true;
}
};
}
function testBreakpointInContext(session) {
console.log('[test]',
'Verifying debugger stops on start (--inspect-brk option)');
const commands = [
{ 'method': 'Runtime.enable' },
{ 'method': 'Debugger.enable' },
{ 'method': 'Runtime.runIfWaitingForDebugger' }
];
session
.sendInspectorCommands(commands)
.expectMessages(setupExpectBreakInContext());
}
function resume(session) {
session
.sendInspectorCommands({ 'method': 'Debugger.resume'})
.disconnect(true);
}
function runTests(harness) {
harness
.runFrontendSession([
testBreakpointInContext,
resume,
]).expectShutDown(0);
}
const script = `
var inspector = require('inspector');
var vm = require('vm');
var sandbox = {};
vm.createContext(sandbox);
inspector.attachContext(sandbox);
vm.runInContext('function testfn() {debugger};testfn();', sandbox);
inspector.detachContext(sandbox);
`;
helper.startNodeForInspectorTest(runTests, '--inspect-brk', script);