summaryrefslogtreecommitdiff
path: root/test/parallel/test-inspect-publish-uid.js
blob: 58d651e97dc64eecc58a75a5d6da90ce53e92c58 (plain)
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
'use strict';
const common = require('../common');

common.skipIfInspectorDisabled();

const assert = require('assert');
const { spawnSync } = require('child_process');

(async function test() {
  await testArg('stderr');
  await testArg('http');
  await testArg('http,stderr');
})();

async function testArg(argValue) {
  console.log('Checks ' + argValue + '..');
  const hasHttp = argValue.split(',').includes('http');
  const hasStderr = argValue.split(',').includes('stderr');

  const nodeProcess = spawnSync(process.execPath, [
    '--inspect=0',
    `--inspect-publish-uid=${argValue}`,
    '-e', `(${scriptMain.toString()})(${hasHttp ? 200 : 404})`
  ]);
  const hasWebSocketInStderr = checkStdError(
    nodeProcess.stderr.toString('utf8'));
  assert.strictEqual(hasWebSocketInStderr, hasStderr);

  function checkStdError(data) {
    const matches = data.toString('utf8').match(/ws:\/\/.+:(\d+)\/.+/);
    return !!matches;
  }

  function scriptMain(code) {
    const url = require('inspector').url();
    const { host } = require('url').parse(url);
    require('http').get('http://' + host + '/json/list', (response) => {
      assert.strictEqual(response.statusCode, code);
      response.destroy();
    });
  }
}