fix(utils): recognize underscore Bun test entrypoints

This commit is contained in:
can1357
2026-08-01 20:07:59 +02:00
parent 5b2aefe584
commit f13f9b1228
2 changed files with 22 additions and 3 deletions
+1 -1
View File
@@ -258,7 +258,7 @@ export function $envpos(name: string, defaultValue: number): number {
return parsed;
}
const BUN_TEST_ENTRY_PATTERN = /\.(?:test|spec)\.[cm]?[jt]sx?$/;
const BUN_TEST_ENTRY_PATTERN = /[._](?:test|spec)\.[cm]?[jt]sx?$/;
/** True when the process is an explicitly marked test child or Bun is running a test entrypoint. */
export function isBunTestRuntime(): boolean {
+21 -2
View File
@@ -40,9 +40,12 @@ describe("getDbBusyTimeoutMs", () => {
}
});
});
async function runRuntimeProbe(env: Record<string, string | undefined>): Promise<boolean> {
async function runRuntimeProbe(
env: Record<string, string | undefined>,
probePath = runtimeProbePath,
): Promise<boolean> {
const cwd = path.dirname(writeTempEnv(""));
const proc = Bun.spawn([process.execPath, runtimeProbePath], {
const proc = Bun.spawn([process.execPath, probePath], {
cwd,
env: { ...process.env, ...env },
stdout: "pipe",
@@ -168,4 +171,20 @@ describe("isBunTestRuntime", () => {
it("honors the private test runner signal", async () => {
expect(await runRuntimeProbe({ NODE_ENV: undefined, BUN_ENV: undefined, PI_TEST_RUNTIME: "1" })).toBe(true);
});
it("recognizes Bun's underscore test entrypoints", async () => {
const dir = path.dirname(writeTempEnv(""));
const underscoreProbePath = path.join(dir, "runtime_test.ts");
const envModulePath = path.join(import.meta.dir, "..", "src", "env.ts");
fs.writeFileSync(
underscoreProbePath,
`import { isBunTestRuntime } from ${JSON.stringify(envModulePath)};\nprocess.stdout.write(JSON.stringify(isBunTestRuntime()));\n`,
);
expect(
await runRuntimeProbe(
{ NODE_ENV: "test", BUN_ENV: undefined, PI_TEST_RUNTIME: undefined },
underscoreProbePath,
),
).toBe(true);
});
});