11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci// This test ensures that Workers have the ability to get 61cb0ef41Sopenharmony_ci// their own command line flags. 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst { Worker } = require('worker_threads'); 91cb0ef41Sopenharmony_ciconst { StringDecoder } = require('string_decoder'); 101cb0ef41Sopenharmony_ciconst decoder = new StringDecoder('utf8'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ci// Do not use isMainThread so that this test itself can be run inside a Worker. 131cb0ef41Sopenharmony_ciif (!process.env.HAS_STARTED_WORKER) { 141cb0ef41Sopenharmony_ci process.env.HAS_STARTED_WORKER = 1; 151cb0ef41Sopenharmony_ci const w = new Worker(__filename, { execArgv: ['--trace-warnings'] }); 161cb0ef41Sopenharmony_ci w.stderr.on('data', common.mustCall((chunk) => { 171cb0ef41Sopenharmony_ci const error = decoder.write(chunk); 181cb0ef41Sopenharmony_ci assert.ok( 191cb0ef41Sopenharmony_ci /Warning: some warning[\s\S]*at Object\.<anonymous>/.test(error) 201cb0ef41Sopenharmony_ci ); 211cb0ef41Sopenharmony_ci })); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci new Worker( 241cb0ef41Sopenharmony_ci "require('worker_threads').parentPort.postMessage(process.execArgv)", 251cb0ef41Sopenharmony_ci { eval: true, execArgv: ['--trace-warnings'] }) 261cb0ef41Sopenharmony_ci .on('message', common.mustCall((data) => { 271cb0ef41Sopenharmony_ci assert.deepStrictEqual(data, ['--trace-warnings']); 281cb0ef41Sopenharmony_ci })); 291cb0ef41Sopenharmony_ci} else { 301cb0ef41Sopenharmony_ci process.emitWarning('some warning'); 311cb0ef41Sopenharmony_ci assert.deepStrictEqual(process.execArgv, ['--trace-warnings']); 321cb0ef41Sopenharmony_ci} 33