Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/funny-hotels-stand.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/testing': patch
---

Update `signInWithEmailAndInstantPassword` to wait for session by default.
2 changes: 1 addition & 1 deletion integration/presets/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next.js v13 does not support next dev --turbo.

.addScript('build', 'pnpm build')
.addScript('serve', 'pnpm start')
.addDependency('next', constants.E2E_NEXTJS_VERSION)
Expand Down
1 change: 1 addition & 0 deletions integration/templates/next-app-router/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const nextConfig = {
experimental: {
serverActions: true,
},
outputFileTracingRoot: '/',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, Turbopack doesn't resolve files outside of the project root. We use pnpm link to install dependencies, which exist outside of the root. We set the outputFileTracingRoot to the root / directory to allow Turbopack to resolve dependency files from anywhere on disk.

};

module.exports = nextConfig;
3 changes: 2 additions & 1 deletion integration/templates/next-app-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
8 changes: 6 additions & 2 deletions integration/tests/next-account-portal/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 15 additions & 3 deletions packages/testing/src/playwright/unstable/page-objects/signIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading