UNPKG

poku

Version:

🐷 Poku makes testing easy for Node.js, Bun, Deno, and you at the same time.

60 lines (59 loc) 2.02 kB
import { createRequire } from "node:module"; import { spawn } from "node:child_process"; import { env } from "node:process"; import { runner, kill } from "./_shared.js"; import { createReporter, findFileFromStack, onSigint, reporter } from "./_shared.js"; import "node:path"; import "node:os"; import "node:assert"; import "node:assert/strict"; import "node:fs/promises"; import "node:net"; const require2 = createRequire(import.meta.url), definePlugin = (plugin) => plugin, pokuBin = (() => { try { return require2.resolve("../bin/index.js"); } catch { return ""; } })(), inspectPoku = (options) => { const { command, spawnOptions, bin = pokuBin } = options, ext = bin.endsWith(".ts") ? "ts" : "js", cmd = runner(`_.${ext}`).join(" "), basePath = typeof spawnOptions?.cwd == "string" ? spawnOptions.cwd.split(/\/|\\/).map(() => "../").join("") : "./", fullCommand = `${cmd} ${basePath}${bin} ${command}`, [runtime, ...args] = fullCommand.split(" "); return new Promise((resolve, reject) => { const childProcess = spawn(runtime, args, { ...spawnOptions, shell: !1, env: { ...spawnOptions?.env || env, POKU_RUNTIME: env.POKU_RUNTIME } }); childProcess.stdout.setEncoding("utf8"), childProcess.stderr.setEncoding("utf8"); const PID = childProcess.pid, kill$1 = async () => { await kill.pid(PID); }; let stdout = "", stderr = ""; childProcess.stdout.on("data", (data) => { stdout += String(data); }), childProcess.stderr.on("data", (data) => { stderr += String(data); }), childProcess.on("error", (error) => { reject({ error: error.message, stdout, stderr, exitCode: 1 }); }), childProcess.on("close", (code) => { resolve({ stdout, stderr, exitCode: code, process: childProcess, PID, kill: kill$1 }); }); }); }; export { createReporter, definePlugin, findFileFromStack, inspectPoku, onSigint, reporter as reporterRegistry };