Skip to content

Commit 41e1dc0

Browse files
Benjamin Coetargos
authored andcommitted
test: add regression test for #11257
Refs: #11257 PR-URL: #20391 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
1 parent 3929516 commit 41e1dc0

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
require('../common');
3+
consttmpdir=require('../common/tmpdir');
4+
constassert=require('assert');
5+
constfs=require('fs');
6+
constjoin=require('path').join;
7+
constspawn=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+
constfakeModulePath=join(tmpdir.path,'batman.js');
15+
conststderrOutputPath=join(tmpdir.path,'stderr-output.txt');
16+
// we need to redirect stderr to a file to produce #11257
17+
conststream=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+
conststderr=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)