summaryrefslogtreecommitdiff
path: root/test/common/require-as.js
blob: 7aba4fa6d825a218f03cd0d77f41f04530bb8f34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/* eslint-disable node-core/require-common-first, node-core/required-modules */
'use strict';

if (require.main !== module) {
  const { spawnSync } = require('child_process');

  function runModuleAs(filename, flags, spawnOptions, role) {
    return spawnSync(process.execPath,
                     [...flags, __filename, role, filename], spawnOptions);
  }

  module.exports = runModuleAs;
  return;
}

const { Worker, isMainThread, workerData } = require('worker_threads');

if (isMainThread) {
  if (process.argv[2] === 'worker') {
    new Worker(__filename, {
      workerData: process.argv[3]
    });
    return;
  }
  require(process.argv[3]);
} else {
  require(workerData);
}