summaryrefslogtreecommitdiff
path: root/test/parallel/test-process-external-stdio-close-spawn.js
blob: f7ee37c44629cd49ce05445b0e0ea447779fba92 (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
'use strict';
// Refs: https://github.com/nodejs/node/issues/947
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');

if (process.argv[2] === 'child') {
  process.on('message', common.mustCall((msg) => {
    assert.strictEqual(msg, 'go');
    // The following console.log is an integral part
    // of the test. If this regress, this call will
    // cause the process to exit with 1
    console.log('logging should not cause a crash');
    process.disconnect();
  }));
} else {
  // Passing '--inspect', '--inspect-brk' to child.spawn enables
  // the debugger. This test was added to help debug the fork-based
  // test with the same name.
  const child = cp.spawn(process.execPath, [__filename, 'child'], {
    stdio: ['pipe', 'pipe', 'pipe', 'ipc']
  });

  child.on('close', common.mustCall((exitCode, signal) => {
    assert.strictEqual(exitCode, 0);
    assert.strictEqual(signal, null);
  }));

  child.stdout.destroy();
  child.send('go');
}