chore(test): use onTestFinished

This commit is contained in:
Alex Yang
2026-01-20 11:27:01 -08:00
parent 684378a991
commit 081e6f20fc

View File

@@ -6,7 +6,7 @@ import type {
} from "@better-auth/core";
import type { SuccessContext } from "@better-fetch/fetch";
import { sql } from "kysely";
import { afterAll } from "vitest";
import { onTestFinished } from "vitest";
import { betterAuth } from "../auth/full";
import { createAuthClient } from "../client";
import { parseSetCookieHeader, setCookieToHeader } from "../cookies";
@@ -16,20 +16,11 @@ import { bearer } from "../plugins";
import type { Session, User } from "../types";
import { getBaseURL } from "../utils/url";
const cleanupSet = new Set<Function>();
type CurrentUserContext = {
headers: Headers;
};
const currentUserContextStorage = new AsyncLocalStorage<CurrentUserContext>();
afterAll(async () => {
for (const cleanup of cleanupSet) {
await cleanup();
cleanupSet.delete(cleanup);
}
});
export async function getTestInstance<
O extends Partial<BetterAuthOptions>,
C extends BetterAuthClientOptions,
@@ -189,7 +180,7 @@ export async function getTestInstance<
return;
}
};
cleanupSet.add(cleanup);
onTestFinished(cleanup);
const customFetchImpl = async (
url: string | URL | Request,