1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const { Worker, isMainThread, workerData } = require('worker_threads'); 5 6if (isMainThread) { 7 assert.throws(() => { 8 new Worker(__filename, { argv: 'foo' }); 9 }, { 10 code: 'ERR_INVALID_ARG_TYPE' 11 }); 12 13 [ 14 new Worker(__filename, { 15 argv: [null, 'foo', 123, Symbol('bar')], 16 // Asserts only if the worker is started by the test. 17 workerData: 'assert-argv' 18 }), 19 new Worker(` 20 const assert = require('assert'); 21 assert.deepStrictEqual( 22 process.argv, 23 [process.execPath, '[worker eval]'] 24 ); 25 `, { 26 eval: true 27 }), 28 new Worker(` 29 const assert = require('assert'); 30 assert.deepStrictEqual( 31 process.argv, 32 [process.execPath, '[worker eval]', 'null', 'foo', '123', 33 String(Symbol('bar'))] 34 ); 35 `, { 36 argv: [null, 'foo', 123, Symbol('bar')], 37 eval: true 38 }), 39 ].forEach((worker) => { 40 worker.on('exit', common.mustCall((code) => { 41 assert.strictEqual(code, 0); 42 })); 43 }); 44} else if (workerData === 'assert-argv') { 45 assert.deepStrictEqual( 46 process.argv, 47 [process.execPath, __filename, 'null', 'foo', '123', String(Symbol('bar'))] 48 ); 49} 50