forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repl: do not run --eval code if there is none
`getOptionValue('--eval')` always returns a string, so it is never loose-equal to `null`. Running eval makes some modifications to the global object, including setting `module` to a different value, which we want to avoid if possible. Refs: nodejs#27278 Fixes: nodejs#27575
- Loading branch information
Showing
2 changed files
with
24 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const child_process = require('child_process'); | ||
const assert = require('assert'); | ||
|
||
// Regression test for https://github.com/nodejs/node/issues/27575: | ||
// module.id === '<repl>' in the REPL. | ||
|
||
for (const extraFlags of [[], ['-e', '42']]) { | ||
const flags = ['--interactive', ...extraFlags]; | ||
const proc = child_process.spawn(process.execPath, flags, { | ||
stdio: ['pipe', 'pipe', 'inherit'] | ||
}); | ||
proc.stdin.write('module.id\n.exit\n'); | ||
|
||
let stdout = ''; | ||
proc.stdout.setEncoding('utf8'); | ||
proc.stdout.on('data', (chunk) => stdout += chunk); | ||
proc.stdout.on('end', common.mustCall(() => { | ||
assert(stdout.includes('<repl>'), `stdout: ${stdout}`); | ||
})); | ||
} |