UNPKG

radashi-helper

Version:
60 lines (58 loc) 1.27 kB
import { stdio } from "./chunk-GGEXN2BI.js"; import { debug, getEnv } from "./chunk-DSXY7YVB.js"; import { exec } from "./chunk-JLKIE3A2.js"; import "./chunk-VOEQFXI5.js"; // src/test.ts import glob from "fast-glob"; async function startTestRunner(globs, { dir, env, ...flags }) { env ??= getEnv(dir); let subCommand; if (globs[0] === "run") { subCommand = "run"; } const args = [ "-s", "vitest", subCommand, "--coverage", ...globs, ...arrifyFlags(flags) ]; if (globs.length > 0) { const globbishRE = /(^src\b|\*)/; const files = await glob( globs.map((glob2) => globbishRE.test(glob2) ? glob2 : `src/**/${glob2}*`), { cwd: process.cwd() } ); for (const file of files) { args.push("--coverage.include", file); } } debug("Running:", ["pnpm", ...args]); await exec("pnpm", args, { cwd: env.root, stdio }); } function arrifyFlags(flags) { return Object.entries(flags).flatMap(([key, value]) => { if (key === "--") { return []; } const name = value === false ? "no-" + key : key; const flag = name.length === 1 ? `-${name}` : `--${name}`; return value === true ? [flag] : [flag, value]; }); } export { startTestRunner };