-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A convenience option to populate `process.argv` in worker threads. PR-URL: #30559 Fixes: #30531 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com>
- Loading branch information
1 parent
2cc0482
commit 81e363a
Showing
4 changed files
with
81 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
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,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'))] | ||
); | ||
} |