UNPKG

poku

Version:

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

69 lines (68 loc) 3.19 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty; var __copyProps = (to, from, except, desc) => { if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target, mod )); var node_child_process = require("node:child_process"), process = require("node:process"), _shared = require("./_shared.cjs"); require("node:path"), require("node:os"), require("node:assert"), require("node:assert/strict"), require("node:fs/promises"), require("node:net"); const definePlugin = (plugin) => plugin, pokuBin = (() => { try { return require.resolve("../bin/index.js"); } catch { return ""; } })(), inspectPoku = (options) => { const { command, spawnOptions, bin = pokuBin } = options, ext = bin.endsWith(".ts") ? "ts" : "js", cmd = _shared.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 = node_child_process.spawn(runtime, args, { ...spawnOptions, shell: !1, env: { ...spawnOptions?.env || process.env, POKU_RUNTIME: process.env.POKU_RUNTIME } }); childProcess.stdout.setEncoding("utf8"), childProcess.stderr.setEncoding("utf8"); const PID = childProcess.pid, kill = async () => { await _shared.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 }); }); }); }; exports.createReporter = _shared.createReporter; exports.findFileFromStack = _shared.findFileFromStack; exports.onSigint = _shared.onSigint; exports.reporterRegistry = _shared.reporter; exports.definePlugin = definePlugin; exports.inspectPoku = inspectPoku;