• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4
5// This test ensures that Workers have the ability to get
6// their own command line flags.
7
8const { Worker } = require('worker_threads');
9const { StringDecoder } = require('string_decoder');
10const decoder = new StringDecoder('utf8');
11
12// Do not use isMainThread so that this test itself can be run inside a Worker.
13if (!process.env.HAS_STARTED_WORKER) {
14  process.env.HAS_STARTED_WORKER = 1;
15  const w = new Worker(__filename, { execArgv: ['--trace-warnings'] });
16  w.stderr.on('data', common.mustCall((chunk) => {
17    const error = decoder.write(chunk);
18    assert.ok(
19      /Warning: some warning[\s\S]*at Object\.<anonymous>/.test(error)
20    );
21  }));
22
23  new Worker(
24    "require('worker_threads').parentPort.postMessage(process.execArgv)",
25    { eval: true, execArgv: ['--trace-warnings'] })
26    .on('message', common.mustCall((data) => {
27      assert.deepStrictEqual(data, ['--trace-warnings']);
28    }));
29} else {
30  process.emitWarning('some warning');
31  assert.deepStrictEqual(process.execArgv, ['--trace-warnings']);
32}
33