Skip to content

Commit 41e1dc0

Browse files
Benjamin Coetargos
Benjamin Coe
authored andcommitted
test: add regression test for #11257
Refs: #11257 PR-URL: #20391 Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
1 parent 3929516 commit 41e1dc0

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
require('../common');
3+
const tmpdir = require('../common/tmpdir');
4+
const assert = require('assert');
5+
const fs = require('fs');
6+
const join = require('path').join;
7+
const spawn = require('child_process').spawnSync;
8+
9+
// Test that invoking node with require, and piping stderr to file,
10+
// does not result in exception,
11+
// see: https://github.com/nodejs/node/issues/11257
12+
13+
tmpdir.refresh();
14+
const fakeModulePath = join(tmpdir.path, 'batman.js');
15+
const stderrOutputPath = join(tmpdir.path, 'stderr-output.txt');
16+
// we need to redirect stderr to a file to produce #11257
17+
const stream = fs.createWriteStream(stderrOutputPath);
18+
19+
// the error described in #11257 only happens when we require a
20+
// non-built-in module.
21+
fs.writeFileSync(fakeModulePath, '', 'utf8');
22+
23+
stream.on('open', () => {
24+
spawn(process.execPath, {
25+
input: `require("${fakeModulePath.replace(/\\/g, '/')}")`,
26+
stdio: ['pipe', 'pipe', stream]
27+
});
28+
const stderr = fs.readFileSync(stderrOutputPath, 'utf8').trim();
29+
assert.strictEqual(
30+
stderr,
31+
'',
32+
`piping stderr to file should not result in exception: ${stderr}`
33+
);
34+
stream.end();
35+
fs.unlinkSync(stderrOutputPath);
36+
fs.unlinkSync(fakeModulePath);
37+
});

0 commit comments

Comments
 (0)