Skip to content

Commit 5774982

Browse files
committed
test(integration): add vinext e2e tests for Clerk on Vite-based Next.js
Add integration test infrastructure and 3 test suites (12 tests) to validate @clerk/nextjs works on vinext (Cloudflare's Vite-based Next.js reimplementation for Workers). Template: integration/templates/vinext-app/ with minimal Clerk app Preset: integration/presets/vinext.ts wired into test framework Tests: quickstart (sign-in/out), protect (auth gating), auth-state (cookie persistence, cross-tab, server/client consistency) All tests tagged @vinext for filtering.
1 parent f166d40 commit 5774982

18 files changed

Lines changed: 474 additions & 0 deletions

File tree

integration/presets/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { nuxt } from './nuxt';
99
import { react } from './react';
1010
import { reactRouter } from './react-router';
1111
import { tanstack } from './tanstack';
12+
import { vinext } from './vinext';
1213
import { vue } from './vue';
1314

1415
export const appConfigs = {
@@ -22,6 +23,7 @@ export const appConfigs = {
2223
astro,
2324
tanstack,
2425
nuxt,
26+
vinext,
2527
vue,
2628
reactRouter,
2729
secrets: {

integration/presets/vinext.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { applicationConfig } from '../models/applicationConfig';
2+
import { templates } from '../templates';
3+
import { linkPackage } from './utils';
4+
5+
const app = applicationConfig()
6+
.setName('vinext-app')
7+
.useTemplate(templates['vinext-app'])
8+
.setEnvFormatter('public', key => `NEXT_PUBLIC_${key}`)
9+
.addScript('setup', 'pnpm install')
10+
.addScript('dev', 'pnpm dev')
11+
.addScript('build', 'pnpm build')
12+
.addScript('serve', 'pnpm start')
13+
.addDependency('@clerk/nextjs', linkPackage('nextjs'))
14+
.addDependency('@clerk/shared', linkPackage('shared'));
15+
16+
export const vinext = { app } as const;

integration/templates/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export const templates = {
2222
'react-router-node': resolve(__dirname, './react-router-node'),
2323
'react-router-library': resolve(__dirname, './react-router-library'),
2424
'custom-flows-react-vite': resolve(__dirname, './custom-flows-react-vite'),
25+
'vinext-app': resolve(__dirname, './vinext-app'),
2526
} as const;
2627

2728
if (new Set([...Object.values(templates)]).size !== Object.values(templates).length) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.next
3+
dist
4+
.vinext
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { auth } from '@clerk/nextjs/server';
2+
3+
export async function GET() {
4+
const authObj = await auth();
5+
return new Response(
6+
JSON.stringify({
7+
userId: authObj.userId,
8+
sessionId: authObj.sessionId,
9+
}),
10+
{
11+
headers: { 'content-type': 'application/json' },
12+
},
13+
);
14+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
'use client';
2+
3+
import { SignInButton, UserButton, useAuth } from '@clerk/nextjs';
4+
5+
export function AuthDisplay() {
6+
const { isSignedIn } = useAuth();
7+
8+
if (isSignedIn) {
9+
return (
10+
<div>
11+
<UserButton />
12+
</div>
13+
);
14+
}
15+
16+
return (
17+
<div>
18+
<SignInButton />
19+
</div>
20+
);
21+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { ClerkProvider } from '@clerk/nextjs';
2+
3+
export default function RootLayout({ children }: { children: React.ReactNode }) {
4+
return (
5+
<ClerkProvider>
6+
<html lang='en'>
7+
<body>{children}</body>
8+
</html>
9+
</ClerkProvider>
10+
);
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { auth } from '@clerk/nextjs/server';
2+
import { AuthDisplay } from './auth-display';
3+
4+
export default async function Home() {
5+
const { userId } = await auth();
6+
return (
7+
<main>
8+
<h1>vinext + Clerk</h1>
9+
<AuthDisplay />
10+
<p data-clerk-user-id={userId || ''}>{userId ? `server-user-id: ${userId}` : 'server-signed-out'}</p>
11+
</main>
12+
);
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { auth } from '@clerk/nextjs/server';
2+
3+
export default async function Protected() {
4+
const { userId } = await auth.protect();
5+
return (
6+
<main>
7+
<h1>Protected Page</h1>
8+
<p>User ID: {userId}</p>
9+
</main>
10+
);
11+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { SignIn } from '@clerk/nextjs';
2+
export default function Page() {
3+
return <SignIn />;
4+
}

0 commit comments

Comments
 (0)