diff --git a/integration/testUtils/appPageObject.ts b/integration/testUtils/appPageObject.ts index 0d5f14b374..8a59157028 100644 --- a/integration/testUtils/appPageObject.ts +++ b/integration/testUtils/appPageObject.ts @@ -13,7 +13,7 @@ export const createAppPageObject = (testArgs: { page: Page }, app: Application) // do not fail the test if interstitial is returned (401) } }, - goToRelative: async (path: string, opts: { searchParams?: URLSearchParams; timeout?: number } = {}) => { + goToRelative: (path: string, opts: { searchParams?: URLSearchParams; timeout?: number } = {}) => { let url: URL; try { @@ -35,7 +35,7 @@ export const createAppPageObject = (testArgs: { page: Page }, app: Application) if (opts.searchParams) { url.search = opts.searchParams.toString(); } - await page.goto(url.toString(), { timeout: opts.timeout ?? 10000 }); + return page.goto(url.toString(), { timeout: opts.timeout ?? 10000 }); }, waitForClerkJsLoaded: async () => { return page.waitForFunction(() => { diff --git a/integration/testUtils/index.ts b/integration/testUtils/index.ts index 6721e0d2ba..7a8c043f20 100644 --- a/integration/testUtils/index.ts +++ b/integration/testUtils/index.ts @@ -1,5 +1,6 @@ import { createClerkClient as backendCreateClerkClient } from '@clerk/backend'; -import type { Browser, BrowserContext, Page } from '@playwright/test'; +import type { Browser, BrowserContext, Page, Response } from '@playwright/test'; +import { expect } from '@playwright/test'; import type { Application } from '../models/application'; import { createAppPageObject } from './appPageObject'; @@ -24,6 +25,13 @@ const createClerkClient = (app: Application) => { const createExpectPageObject = ({ page }: TestArgs) => { return { + toBeHandshake: async (res: Response) => { + // Travel the redirect chain until we find the handshake header + // TODO: Loop through the redirects until we find a handshake header, or timeout trying + const redirect = await res.request().redirectedFrom().redirectedFrom().redirectedFrom().response(); + expect(redirect.status()).toBe(307); + expect(redirect.headers()['x-clerk-auth-status']).toContain('handshake'); + }, toBeSignedOut: () => { return page.waitForFunction(() => { return !window.Clerk?.user; diff --git a/integration/testUtils/signInPageObject.ts b/integration/testUtils/signInPageObject.ts index f0509e81c7..ffee57fd46 100644 --- a/integration/testUtils/signInPageObject.ts +++ b/integration/testUtils/signInPageObject.ts @@ -12,13 +12,14 @@ export const createSignInComponentPageObject = (testArgs: TestArgs) => { const self = { ...common(testArgs), goTo: async (opts?: { searchParams?: URLSearchParams; headlessSelector?: string; timeout?: number }) => { - await page.goToRelative('/sign-in', opts); + const navRes = await page.goToRelative('/sign-in', opts); if (typeof opts?.headlessSelector !== 'undefined') { - return self.waitForMounted(opts.headlessSelector); + await self.waitForMounted(opts.headlessSelector); } else { - return self.waitForMounted(); + await self.waitForMounted(); } + return navRes; }, waitForMounted: (selector = '.cl-signIn-root') => { return page.waitForSelector(selector, { state: 'attached' }); diff --git a/integration/tests/sessions/root-subdomain-prod-instances.test.ts b/integration/tests/sessions/root-subdomain-prod-instances.test.ts index a185d246e5..009b3dd3dd 100644 --- a/integration/tests/sessions/root-subdomain-prod-instances.test.ts +++ b/integration/tests/sessions/root-subdomain-prod-instances.test.ts @@ -239,8 +239,9 @@ test.describe('root and subdomain production apps @sessions', () => { // The client_uat cookie should always be set on etld+1 expect(tab0Cookies.get('__client_uat_*').domain).toEqual('.' + hosts[0]); - await u[1].page.goto(`https://${hosts[1]}`); + u[1].po.expect.toBeHandshake(await u[1].page.goto(`https://${hosts[1]}`)); await u[1].po.expect.toBeSignedOut(); + expect((await u[1].page.evaluate(() => fetch('/api/me').then(r => r.json()))).userId).toBe(null); await u[1].po.signIn.goTo(); await u[1].po.signIn.signInWithEmailAndInstantPassword(fakeUsers[1]);