0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-inspector-multisession-js.js
Anna Henningsen e2ea73af04
test: make sure that inspector tests finish
PR-URL: https://github.com/nodejs/node/pull/32673
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2020-04-08 16:43:13 +02:00

64 lines
1.5 KiB
JavaScript

// Flags: --expose-internals
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const assert = require('assert');
const { Session } = require('inspector');
const path = require('path');
const { pathToFileURL } = require('url');
function debugged() {
return 42;
}
async function test() {
const session1 = new Session();
const session2 = new Session();
session1.connect();
session2.connect();
let session1Paused = false;
let session2Paused = false;
session1.on('Debugger.paused', () => session1Paused = true);
session2.on('Debugger.paused', () => session2Paused = true);
console.log('Connected');
session1.post('Debugger.enable');
session2.post('Debugger.enable');
console.log('Debugger was enabled');
await new Promise((resolve, reject) => {
session1.post('Debugger.setBreakpointByUrl', {
'lineNumber': 12,
'url': pathToFileURL(path.resolve(__dirname, __filename)).toString(),
'columnNumber': 0,
'condition': ''
}, (error, result) => {
return error ? reject(error) : resolve(result);
});
});
console.log('Breakpoint was set');
debugged();
// Both sessions will receive the paused event
assert(session1Paused);
assert(session2Paused);
console.log('Breakpoint was hit');
session1.disconnect();
session2.disconnect();
console.log('Sessions were disconnected');
}
const interval = setInterval(() => {}, 1000);
test().then(common.mustCall(() => {
clearInterval(interval);
console.log('Done!');
}));