11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled(); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst { spawnSync } = require('child_process'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci(async function test() { 101cb0ef41Sopenharmony_ci await testArg('stderr'); 111cb0ef41Sopenharmony_ci await testArg('http'); 121cb0ef41Sopenharmony_ci await testArg('http,stderr'); 131cb0ef41Sopenharmony_ci})().then(common.mustCall()); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciasync function testArg(argValue) { 161cb0ef41Sopenharmony_ci console.log('Checks ' + argValue + '..'); 171cb0ef41Sopenharmony_ci const hasHttp = argValue.split(',').includes('http'); 181cb0ef41Sopenharmony_ci const hasStderr = argValue.split(',').includes('stderr'); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci const nodeProcess = spawnSync(process.execPath, [ 211cb0ef41Sopenharmony_ci '--inspect=0', 221cb0ef41Sopenharmony_ci `--inspect-publish-uid=${argValue}`, 231cb0ef41Sopenharmony_ci '-e', `(${scriptMain.toString()})(${hasHttp ? 200 : 404})`, 241cb0ef41Sopenharmony_ci ]); 251cb0ef41Sopenharmony_ci const hasWebSocketInStderr = checkStdError( 261cb0ef41Sopenharmony_ci nodeProcess.stderr.toString('utf8')); 271cb0ef41Sopenharmony_ci assert.strictEqual(hasWebSocketInStderr, hasStderr); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci function checkStdError(data) { 301cb0ef41Sopenharmony_ci const matches = data.toString('utf8').match(/ws:\/\/.+:(\d+)\/.+/); 311cb0ef41Sopenharmony_ci return !!matches; 321cb0ef41Sopenharmony_ci } 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci function scriptMain(code) { 351cb0ef41Sopenharmony_ci const url = require('inspector').url(); 361cb0ef41Sopenharmony_ci const { host } = require('url').parse(url); 371cb0ef41Sopenharmony_ci require('http').get('http://' + host + '/json/list', (response) => { 381cb0ef41Sopenharmony_ci assert.strictEqual(response.statusCode, code); 391cb0ef41Sopenharmony_ci response.destroy(); 401cb0ef41Sopenharmony_ci }); 411cb0ef41Sopenharmony_ci } 421cb0ef41Sopenharmony_ci} 43