summaryrefslogtreecommitdiff
path: root/test/parallel/test-repl-cli-eval.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-05-06 21:54:32 +0200
committerAnna Henningsen <anna@addaleax.net>2019-05-12 15:04:27 +0200
commitf2a48c8245e93939987d2df1bfd5e9c42899b045 (patch)
treee7cdce782d97bdc76afba5f9ea95afd10f60b896 /test/parallel/test-repl-cli-eval.js
parent1d31c6833df85cd913c241cdc4b4d702490fee7b (diff)
downloadandroid-node-v8-f2a48c8245e93939987d2df1bfd5e9c42899b045.tar.gz
android-node-v8-f2a48c8245e93939987d2df1bfd5e9c42899b045.tar.bz2
android-node-v8-f2a48c8245e93939987d2df1bfd5e9c42899b045.zip
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: https://github.com/nodejs/node/pull/27278 PR-URL: https://github.com/nodejs/node/pull/27587 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'test/parallel/test-repl-cli-eval.js')
-rw-r--r--test/parallel/test-repl-cli-eval.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/parallel/test-repl-cli-eval.js b/test/parallel/test-repl-cli-eval.js
new file mode 100644
index 0000000000..6069a20957
--- /dev/null
+++ b/test/parallel/test-repl-cli-eval.js
@@ -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}`);
+ }));
+}