* @param {string} dir * @param {string[]} args * @param {CliTestOptions} options
(dir, args, options)
| 43 | * @param {CliTestOptions} options |
| 44 | */ |
| 45 | function runCliWorker(dir, args, options) { |
| 46 | const result = { |
| 47 | status: undefined, |
| 48 | stdout: "", |
| 49 | stderr: "", |
| 50 | write: [], |
| 51 | }; |
| 52 | const { promise, resolve, reject } = promiseWithResolvers(); |
| 53 | const createEpipeErrorHandler = (event) => (error) => { |
| 54 | if (!error) { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | // It can fail with `write EPIPE` error when running node with unsupported flags like `--experimental-strip-types` |
| 59 | // Let's ignore and wait for the `close` event |
| 60 | if ( |
| 61 | error.code === "EPIPE" && |
| 62 | error.syscall === "write" && |
| 63 | nodeOptions.length > 0 |
| 64 | ) { |
| 65 | if (IS_CI) { |
| 66 | // eslint-disable-next-line no-console |
| 67 | console.error( |
| 68 | Object.assign(error, { event, dir, args, options, worker }), |
| 69 | ); |
| 70 | } |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | reject(error); |
| 75 | }; |
| 76 | |
| 77 | const nodeOptions = options?.nodeOptions ?? []; |
| 78 | const env = { |
| 79 | ...process.env, |
| 80 | ...options.env, |
| 81 | NO_COLOR: "1", |
| 82 | }; |
| 83 | delete env.FORCE_COLOR; |
| 84 | |
| 85 | const worker = childProcess.fork(CLI_WORKER_FILE, args, { |
| 86 | cwd: dir, |
| 87 | execArgv: [ |
| 88 | "--trace-deprecation", |
| 89 | ...(SUPPORTS_DISABLE_WARNING_FLAG |
| 90 | ? ["--disable-warning=ExperimentalWarning"] |
| 91 | : []), |
| 92 | ...nodeOptions, |
| 93 | ], |
| 94 | stdio: [options.input ? "pipe" : "ignore", "pipe", "pipe", "ipc"], |
| 95 | env, |
| 96 | serialization: "advanced", |
| 97 | }); |
| 98 | |
| 99 | worker.on("message", (message) => { |
| 100 | if (message.type === "cli:write-file") { |
| 101 | result.write.push(message.data); |
| 102 | } else if (message.type === "worker:fault") { |
no test coverage detected
searching dependent graphs…