summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-02-08 11:22:37 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-02-10 16:34:19 +0800
commit69714ab1c44f45f7949484ab7f4574f3ad9894ce (patch)
treed3e170836403e699068933bb3d743ef48c55060e /test
parent84000835e2be2e5b1936d774ed4c4a0106c966a4 (diff)
downloadandroid-node-v8-69714ab1c44f45f7949484ab7f4574f3ad9894ce.tar.gz
android-node-v8-69714ab1c44f45f7949484ab7f4574f3ad9894ce.tar.bz2
android-node-v8-69714ab1c44f45f7949484ab7f4574f3ad9894ce.zip
process: normalize process.argv before user code execution
And make sure that `process.argv` from the preloaded modules is the same as the one in the main module. Refs: https://github.com/nodejs/node/issues/25967 PR-URL: https://github.com/nodejs/node/pull/26000 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Diffstat (limited to 'test')
-rw-r--r--test/parallel/test-preload-print-process-argv.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/test/parallel/test-preload-print-process-argv.js b/test/parallel/test-preload-print-process-argv.js
new file mode 100644
index 0000000000..ace20dfb39
--- /dev/null
+++ b/test/parallel/test-preload-print-process-argv.js
@@ -0,0 +1,38 @@
+'use strict';
+
+// This tests that process.argv is the same in the preloaded module
+// and the user module.
+
+const common = require('../common');
+
+const tmpdir = require('../common/tmpdir');
+const assert = require('assert');
+const { spawnSync } = require('child_process');
+const fs = require('fs');
+
+if (!common.isMainThread) {
+ common.skip('Cannot chdir to the tmp directory in workers');
+}
+
+tmpdir.refresh();
+
+process.chdir(tmpdir.path);
+fs.writeFileSync(
+ 'preload.js',
+ 'console.log(JSON.stringify(process.argv));',
+ 'utf-8');
+
+fs.writeFileSync(
+ 'main.js',
+ 'console.log(JSON.stringify(process.argv));',
+ 'utf-8');
+
+const child = spawnSync(process.execPath, ['-r', './preload.js', 'main.js']);
+
+if (child.status !== 0) {
+ console.log(child.stderr.toString());
+ assert.strictEqual(child.status, 0);
+}
+
+const lines = child.stdout.toString().trim().split('\n');
+assert.deepStrictEqual(JSON.parse(lines[0]), JSON.parse(lines[1]));