summaryrefslogtreecommitdiff
path: root/test/parallel/test-debugger-pid.js
blob: f269ff310b145c0add03e1ae40ba08969e4bf315 (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
43
44
45
46
47
48
49
50
51
52
53
'use strict';
const common = require('../common');
common.skipIfInspectorDisabled();
const assert = require('assert');
const spawn = require('child_process').spawn;

let buffer = '';

// Connect to debug agent
const interfacer = spawn(process.execPath, ['debug', '-p', '655555']);

interfacer.stdout.setEncoding('utf-8');
interfacer.stderr.setEncoding('utf-8');
const onData = (data) => {
  data = (buffer + data).split('\n');
  buffer = data.pop();
  data.forEach(function(line) {
    interfacer.emit('line', line);
  });
};
interfacer.stdout.on('data', onData);
interfacer.stderr.on('data', onData);

let lineCount = 0;
interfacer.on('line', function(line) {
  let expected;
  const pid = interfacer.pid;
  switch (++lineCount) {
    case 1:
      expected =
        new RegExp(`^\\(node:${pid}\\) \\[DEP0068\\] DeprecationWarning: `);
      assert.ok(expected.test(line), `expected regexp match for ${line}`);
      break;
    case 2:
      // Doesn't currently work on Windows.
      if (!common.isWindows) {
        expected = "Target process: 655555 doesn't exist.";
        assert.strictEqual(line, expected);
      }
      break;

    default:
      if (!common.isWindows)
        assert.fail(`unexpected line received: ${line}`);
  }
});

interfacer.on('exit', function(code, signal) {
  assert.strictEqual(code, 1, `Got unexpected code: ${code}`);
  if (!common.isWindows) {
    assert.strictEqual(lineCount, 2);
  }
});