diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-02-22 21:01:22 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-03-02 13:16:35 +0100 |
commit | f65b4afaea14446c4b313595c03b737ab710c124 (patch) | |
tree | 8c424301f605bcc6f0cd715c0822adb75c9f309f /test/parallel/test-process-exec-argv.js | |
parent | b8018f407b2ae2daa70d41b2aa9dbbc5ca921b0f (diff) | |
download | android-node-v8-f65b4afaea14446c4b313595c03b737ab710c124.tar.gz android-node-v8-f65b4afaea14446c4b313595c03b737ab710c124.tar.bz2 android-node-v8-f65b4afaea14446c4b313595c03b737ab710c124.zip |
worker: provide process.execArgv
Provide `process.execArgv`. If an `execArgv` option is passed to the
`Worker` constructor, that option is used as its value; if not,
the parent’s `process.execArgv` is inherited (since that also goes
for the actual options in that case).
PR-URL: https://github.com/nodejs/node/pull/26267
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-process-exec-argv.js')
-rw-r--r-- | test/parallel/test-process-exec-argv.js | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/test/parallel/test-process-exec-argv.js b/test/parallel/test-process-exec-argv.js index 578ee7b5d1..6321f15177 100644 --- a/test/parallel/test-process-exec-argv.js +++ b/test/parallel/test-process-exec-argv.js @@ -20,26 +20,46 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const spawn = require('child_process').spawn; +const { Worker, isMainThread } = require('worker_threads'); -if (process.argv[2] === 'child') { - process.stdout.write(JSON.stringify(process.execArgv)); +if (process.argv[2] === 'child' || !isMainThread) { + if (process.argv[3] === 'cp+worker') + new Worker(__filename); + else + process.stdout.write(JSON.stringify(process.execArgv)); } else { for (const extra of [ [], [ '--' ] ]) { - const execArgv = ['--stack-size=256']; - const args = [__filename, 'child', 'arg0']; - const child = spawn(process.execPath, [...execArgv, ...extra, ...args]); - let out = ''; + for (const kind of [ 'cp', 'worker', 'cp+worker' ]) { + const execArgv = ['--pending-deprecation']; + const args = [__filename, 'child', kind]; + let child; + switch (kind) { + case 'cp': + child = spawn(process.execPath, [...execArgv, ...extra, ...args]); + break; + case 'worker': + child = new Worker(__filename, { + execArgv: [...execArgv, ...extra], + stdout: true + }); + break; + case 'cp+worker': + child = spawn(process.execPath, [...execArgv, ...args]); + break; + } - child.stdout.setEncoding('utf8'); - child.stdout.on('data', function(chunk) { - out += chunk; - }); + let out = ''; + child.stdout.setEncoding('utf8'); + child.stdout.on('data', (chunk) => { + out += chunk; + }); - child.on('close', function() { - assert.deepStrictEqual(JSON.parse(out), execArgv); - }); + child.stdout.on('end', common.mustCall(() => { + assert.deepStrictEqual(JSON.parse(out), execArgv); + })); + } } } |