diff --git a/.changeset/funny-hotels-stand.md b/.changeset/funny-hotels-stand.md new file mode 100644 index 00000000000..6e1e292b14a --- /dev/null +++ b/.changeset/funny-hotels-stand.md @@ -0,0 +1,5 @@ +--- +'@clerk/testing': patch +--- + +Update `signInWithEmailAndInstantPassword` to wait for session by default. diff --git a/integration/presets/next.ts b/integration/presets/next.ts index a44dc9c6e1e..e2397d2a236 100644 --- a/integration/presets/next.ts +++ b/integration/presets/next.ts @@ -8,7 +8,7 @@ const appRouter = applicationConfig() .useTemplate(templates['next-app-router']) .setEnvFormatter('public', key => `NEXT_PUBLIC_${key}`) .addScript('setup', constants.E2E_NPM_FORCE ? 'pnpm install --force' : 'pnpm install') - .addScript('dev', 'pnpm dev') + .addScript('dev', constants.E2E_NEXTJS_VERSION === '13' ? 'pnpm dev:webpack' : 'pnpm dev') .addScript('build', 'pnpm build') .addScript('serve', 'pnpm start') .addDependency('next', constants.E2E_NEXTJS_VERSION) diff --git a/integration/templates/next-app-router/next.config.js b/integration/templates/next-app-router/next.config.js index 35b183b6064..4b01655c99d 100644 --- a/integration/templates/next-app-router/next.config.js +++ b/integration/templates/next-app-router/next.config.js @@ -6,6 +6,7 @@ const nextConfig = { experimental: { serverActions: true, }, + outputFileTracingRoot: '/', }; module.exports = nextConfig; diff --git a/integration/templates/next-app-router/package.json b/integration/templates/next-app-router/package.json index c574d569ce3..285fb5d7d0d 100644 --- a/integration/templates/next-app-router/package.json +++ b/integration/templates/next-app-router/package.json @@ -4,7 +4,8 @@ "private": true, "scripts": { "build": "next build", - "dev": "next dev", + "dev": "next dev --turbo", + "dev:webpack": "next dev", "lint": "next lint", "start": "next start" }, diff --git a/integration/tests/next-account-portal/common.ts b/integration/tests/next-account-portal/common.ts index 9ce7dad1589..2cdf16a397d 100644 --- a/integration/tests/next-account-portal/common.ts +++ b/integration/tests/next-account-portal/common.ts @@ -159,8 +159,12 @@ export const testSSR = async ({ app, page, context, fakeUser }: TestParams) => { await u.page.getByRole('button', { name: /Sign in/i }).click(); await u.po.signIn.waitForMounted(); - // Sign in with email and password - await u.po.signIn.signInWithEmailAndInstantPassword({ email: fakeUser.email, password: fakeUser.password }); + // Sign in with email and password. If we wait for the session, we will miss the initial redirect back to localhost. + await u.po.signIn.signInWithEmailAndInstantPassword({ + email: fakeUser.email, + password: fakeUser.password, + waitForSession: false, + }); // Navigate back to localhost const response = await page.waitForResponse( diff --git a/packages/testing/src/playwright/unstable/page-objects/common.ts b/packages/testing/src/playwright/unstable/page-objects/common.ts index 618a0957db4..af562c94b8b 100644 --- a/packages/testing/src/playwright/unstable/page-objects/common.ts +++ b/packages/testing/src/playwright/unstable/page-objects/common.ts @@ -51,6 +51,11 @@ export const common = ({ page }: { page: EnhancedPage }) => { getLastNameInput: () => { return page.locator('input[name=lastName]'); }, + waitForSession: async () => { + return page.waitForFunction(() => { + return !!window.Clerk?.session; + }); + }, }; return self; diff --git a/packages/testing/src/playwright/unstable/page-objects/signIn.ts b/packages/testing/src/playwright/unstable/page-objects/signIn.ts index 3196aab6785..38b05df6282 100644 --- a/packages/testing/src/playwright/unstable/page-objects/signIn.ts +++ b/packages/testing/src/playwright/unstable/page-objects/signIn.ts @@ -63,13 +63,25 @@ export const createSignInComponentPageObject = (testArgs: { page: EnhancedPage } signInWithOauth: (provider: string) => { return page.getByRole('button', { name: new RegExp(`continue with ${provider}`, 'gi') }); }, - signInWithEmailAndInstantPassword: async (opts: { email: string; password: string }) => { + signInWithEmailAndInstantPassword: async ({ + email, + password, + waitForSession = true, + }: { + email: string; + password: string; + waitForSession?: boolean; + }) => { const identifierField = self.getIdentifierInput(); await expect(identifierField).toBeVisible(); - await identifierField.fill(opts.email); - await self.setInstantPassword(opts.password); + await identifierField.fill(email); + await self.setInstantPassword(password); await self.continue(); + + if (waitForSession) { + await self.waitForSession(); + } }, }; return self;