Files
cfw-autumn/server/tests/setup-integration-tests.ts
SirTenzin ede28d7fc0 Centralize past-due reset gating
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
2026-04-23 16:53:28 +00:00

42 lines
1.1 KiB
TypeScript

import { execSync } from "node:child_process";
import { loadLocalEnv } from "@/utils/envUtils";
const isUnitTest = () => {
return process.argv.some((arg) => arg.includes("unit"));
};
const loadInfisicalSecrets = async () => {
try {
const secrets = execSync(
"infisical secrets --env=dev --output=dotenv --recursive --silent",
{ encoding: "utf-8" },
);
for (const line of secrets.split("\n")) {
const match = line.match(/^([^=]+)=(.*)$/);
if (match) {
const key = match[1];
if (process.env[key] !== undefined) continue;
process.env[key] = match[2].replace(/^["']|["']$/g, "");
}
}
} catch (e) {
console.warn("Failed to load infisical secrets:", e);
}
};
/**
* Bun test preload script for integration tests.
* Loads environment variables before any test file runs.
*/
if (isUnitTest()) {
console.log("--- Skipping integration setup for unit tests ---");
} else {
console.log("--- Setup integration tests ---");
await loadInfisicalSecrets();
loadLocalEnv({ force: true });
console.log("--- Setup integration tests complete ---");
}