Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 41e1dc0

Browse filesBrowse 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
Copy full SHA for 41e1dc0

File tree

Expand file treeCollapse file tree

1 file changed

+37
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+37
-0
lines changed
Open diff view settings
Collapse file
+37Lines changed: 37 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.