diff options
author | legendecas <legendecas@gmail.com> | 2019-11-21 00:55:36 +0800 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-12-03 23:44:10 +0100 |
commit | 3ebae6cf1b20ce104423214d75c3c84129a8f141 (patch) | |
tree | 12fd6bcfb86f17d050e4c04402c4ab188bb8cd5e /test | |
parent | a025c5a8745637aa5f6e06acab0c15461a920d8e (diff) | |
download | android-node-v8-3ebae6cf1b20ce104423214d75c3c84129a8f141.tar.gz android-node-v8-3ebae6cf1b20ce104423214d75c3c84129a8f141.tar.bz2 android-node-v8-3ebae6cf1b20ce104423214d75c3c84129a8f141.zip |
worker: add argv constructor option
A convenience option to populate `process.argv` in worker threads.
PR-URL: https://github.com/nodejs/node/pull/30559
Fixes: https://github.com/nodejs/node/issues/30531
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-worker-process-argv.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/parallel/test-worker-process-argv.js b/test/parallel/test-worker-process-argv.js new file mode 100644 index 0000000000..ebdebe02ab --- /dev/null +++ b/test/parallel/test-worker-process-argv.js @@ -0,0 +1,49 @@ +'use strict'; +const common = require('../common'); +const assert = require('assert'); +const { Worker, isMainThread, workerData } = require('worker_threads'); + +if (isMainThread) { + assert.throws(() => { + new Worker(__filename, { argv: 'foo' }); + }, { + code: 'ERR_INVALID_ARG_TYPE' + }); + + [ + new Worker(__filename, { + argv: [null, 'foo', 123, Symbol('bar')], + // Asserts only if the worker is started by the test. + workerData: 'assert-argv' + }), + new Worker(` + const assert = require('assert'); + assert.deepStrictEqual( + process.argv, + [process.execPath, '[worker eval]'] + ); + `, { + eval: true + }), + new Worker(` + const assert = require('assert'); + assert.deepStrictEqual( + process.argv, + [process.execPath, '[worker eval]', 'null', 'foo', '123', + String(Symbol('bar'))] + ); + `, { + argv: [null, 'foo', 123, Symbol('bar')], + eval: true + }) + ].forEach((worker) => { + worker.on('exit', common.mustCall((code) => { + assert.strictEqual(code, 0); + })); + }); +} else if (workerData === 'assert-argv') { + assert.deepStrictEqual( + process.argv, + [process.execPath, __filename, 'null', 'foo', '123', String(Symbol('bar'))] + ); +} |