import { formatCmd } from "node_modules/zx/build/util"; import { $, minimist } from "zx"; import { getTestEnvVariables } from "./libs/test/getTestEnv"; const args = minimist(process.argv.slice(2)); if (!args["dbCommand"]) { throw new Error("dbCommand is required"); } const filteredKeys = new Set(["_", "dbCommand", "db", "$0", "db-command"]); const positionalArgs = Object.entries(args) .filter(([key]) => !filteredKeys.has(key)) .map(([key, value]) => { if (typeof value === "boolean") { return `--${key}`; } return `--${key}=${value}`; }) .concat(args._); console.log(formatCmd(args["dbCommand"])); const dbProcess = $({ quote: (arg) => arg })`${args["dbCommand"]}`.nothrow(); $.env = { ...getTestEnvVariables(), PATH: process.env["PATH"], HOME: process.env["HOME"], SHOULD_LOG_ERRORS: process.env["SHOULD_LOG_ERRORS"] ?? "true", }; await $`bun db:migrate`.nothrow(); await $({ verbose: true, quote: (arg) => arg, })`FORCE_COLOR=1 bun test ${positionalArgs.join(" ")}`.nothrow(); await dbProcess.kill("SIGINT");