From 582cb214e90857feb7a564dd09edd416ad7f6969 Mon Sep 17 00:00:00 2001 From: "arrz.dev" <55147716+arrzdev@users.noreply.github.com> Date: Tue, 17 Nov 2026 08:05:36 +0000 Subject: [PATCH] test(e2e): sign out in the cookie smoke test even when it fails The session cookie test signed out only after its assertions passed, so a failed run left the QA session row behind until it expired. Sign-out now runs in a finally block; its status check is soft so it never hides the assertion error. --- e2e/smoke.spec.ts | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/e2e/smoke.spec.ts b/e2e/smoke.spec.ts index ee98840b..3372ac4e 100644 --- a/e2e/smoke.spec.ts +++ b/e2e/smoke.spec.ts @@ -94,25 +94,29 @@ test.describe("deployed environment", () => { headers, }) expect(signIn.status()).toBe(200) - const sessionCookie = signIn - .headersArray() - .filter((header) => header.name.toLowerCase() === "set-cookie") - .map((header) => header.value) - .find((cookie) => cookie.includes("session_token=")) - // only the attributes, so a failure never prints the token - const attributes = sessionCookie - ?.split(";") - .slice(1) - .map((attribute) => attribute.trim().toLowerCase()) - expect(attributes).toEqual( - expect.arrayContaining(["secure", "httponly", "samesite=lax"]), - ) - - // better-auth refuses a POST without a JSON body (415) - const signOut = await request.post("/api/v1/auth/sign-out", { - data: {}, - headers, - }) - expect(signOut.status()).toBe(200) + // sign out even when an assertion fails, so no session row is left behind + try { + const sessionCookie = signIn + .headersArray() + .filter((header) => header.name.toLowerCase() === "set-cookie") + .map((header) => header.value) + .find((cookie) => cookie.includes("session_token=")) + // only the attributes, so a failure never prints the token + const attributes = sessionCookie + ?.split(";") + .slice(1) + .map((attribute) => attribute.trim().toLowerCase()) + expect(attributes).toEqual( + expect.arrayContaining(["secure", "httponly", "samesite=lax"]), + ) + } finally { + // better-auth refuses a POST without a JSON body (415) + const signOut = await request.post("/api/v1/auth/sign-out", { + data: {}, + headers, + }) + // soft, so a failed sign-out never hides the assertion error above + expect.soft(signOut.status()).toBe(200) + } }) })