test: wrap with describe block

This commit is contained in:
Taesu
2026-01-07 12:14:17 +09:00
committed by Alex Yang
parent ef7bfc9a3e
commit bd26c93dd6

View File

@@ -1,5 +1,5 @@
import type { BetterAuthOptions } from "@better-auth/core";
import { describe, expect, it, vi } from "vitest";
import { afterEach, describe, expect, it, vi } from "vitest";
import {
expireCookie,
getCookieCache,
@@ -99,38 +99,41 @@ describe("cookies", async () => {
);
});
it("should use secure cookies in production when baseURL is not configured", async () => {
// Set NODE_ENV to production
vi.stubEnv("NODE_ENV", "production");
// Reset modules to reload with new NODE_ENV
vi.resetModules();
// Re-import modules after NODE_ENV change
const { getTestInstance: getTestInstanceReloaded } = await import(
"../test-utils/test-instance"
);
const { client, testUser } = await getTestInstanceReloaded({
baseURL: undefined,
describe("production environment", () => {
afterEach(() => {
vi.unstubAllEnvs();
vi.resetModules();
});
await client.signIn.email(
{
email: testUser.email,
password: testUser.password,
},
{
onResponse(context) {
const setCookie = context.response.headers.get("set-cookie");
expect(setCookie).toContain("Secure");
},
},
);
it("should use secure cookies when baseURL is not configured", async () => {
// Set NODE_ENV to production
vi.stubEnv("NODE_ENV", "production");
// Clean up
vi.unstubAllEnvs();
vi.resetModules();
// Reset modules to reload with new NODE_ENV
vi.resetModules();
// Re-import modules after NODE_ENV change
const { getTestInstance: getTestInstanceReloaded } = await import(
"../test-utils/test-instance"
);
const { client, testUser } = await getTestInstanceReloaded({
baseURL: undefined,
});
await client.signIn.email(
{
email: testUser.email,
password: testUser.password,
},
{
onResponse(context) {
const setCookie = context.response.headers.get("set-cookie");
expect(setCookie).toContain("Secure");
},
},
);
});
});
});