1'use strict'; 2const common = require('../common'); 3 4common.skipIfInspectorDisabled(); 5 6const assert = require('assert'); 7const { spawnSync } = require('child_process'); 8 9(async function test() { 10 await testArg('stderr'); 11 await testArg('http'); 12 await testArg('http,stderr'); 13})().then(common.mustCall()); 14 15async function testArg(argValue) { 16 console.log('Checks ' + argValue + '..'); 17 const hasHttp = argValue.split(',').includes('http'); 18 const hasStderr = argValue.split(',').includes('stderr'); 19 20 const nodeProcess = spawnSync(process.execPath, [ 21 '--inspect=0', 22 `--inspect-publish-uid=${argValue}`, 23 '-e', `(${scriptMain.toString()})(${hasHttp ? 200 : 404})`, 24 ]); 25 const hasWebSocketInStderr = checkStdError( 26 nodeProcess.stderr.toString('utf8')); 27 assert.strictEqual(hasWebSocketInStderr, hasStderr); 28 29 function checkStdError(data) { 30 const matches = data.toString('utf8').match(/ws:\/\/.+:(\d+)\/.+/); 31 return !!matches; 32 } 33 34 function scriptMain(code) { 35 const url = require('inspector').url(); 36 const { host } = require('url').parse(url); 37 require('http').get('http://' + host + '/json/list', (response) => { 38 assert.strictEqual(response.statusCode, code); 39 response.destroy(); 40 }); 41 } 42} 43