• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const child_process = require('child_process');
5const fixtures = require('../common/fixtures');
6
7const testScript = fixtures.path('catch-stdout-error.js');
8
9const cmd = `${JSON.stringify(process.execPath)} ` +
10            `${JSON.stringify(testScript)} | ` +
11            `${JSON.stringify(process.execPath)} ` +
12            '-pe "process.stdin.on(\'data\' , () => process.exit(1))"';
13
14const child = child_process.exec(cmd);
15let output = '';
16const outputExpect = {
17  code: 'EPIPE',
18  errno: 'EPIPE',
19  syscall: 'write'
20};
21
22child.stderr.on('data', function(c) {
23  output += c;
24});
25
26
27child.on('close', common.mustCall(function(code) {
28  try {
29    output = JSON.parse(output);
30  } catch {
31    console.error(output);
32    process.exit(1);
33  }
34
35  assert.deepStrictEqual(output, outputExpect);
36  console.log('ok');
37}));
38