1'use strict'; 2const common = require('../common'); 3 4common.skipIfInspectorDisabled(); 5 6const assert = require('assert'); 7const { NodeInstance } = require('../common/inspector-helper.js'); 8const os = require('os'); 9 10const ip = pickIPv4Address(); 11 12if (!ip) 13 common.skip('No IP address found'); 14 15function checkIpAddress(ip, response) { 16 const res = response[0]; 17 const wsUrl = res.webSocketDebuggerUrl; 18 assert.ok(wsUrl); 19 const match = wsUrl.match(/^ws:\/\/(.*):\d+\/(.*)/); 20 assert.strictEqual(ip, match[1]); 21 assert.strictEqual(res.id, match[2]); 22 assert.strictEqual(ip, res.devtoolsFrontendUrl.match(/.*ws=(.*):\d+/)[1]); 23} 24 25function pickIPv4Address() { 26 for (const i of [].concat(...Object.values(os.networkInterfaces()))) { 27 if (i.family === 'IPv4' && i.address !== '127.0.0.1') 28 return i.address; 29 } 30} 31 32async function test() { 33 const instance = new NodeInstance('--inspect-brk=0.0.0.0:0'); 34 try { 35 checkIpAddress(ip, await instance.httpGet(ip, '/json/list')); 36 } catch (error) { 37 if (error.code === 'EHOSTUNREACH') { 38 common.printSkipMessage('Unable to connect to self'); 39 } else { 40 throw error; 41 } 42 } 43 instance.kill(); 44} 45 46test().then(common.mustCall()); 47