@clerk/testing: clerkSetup() doesn't fall back to NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
Description
clerkSetup() from @clerk/testing/playwright requires the env var CLERK_PUBLISHABLE_KEY to be set. However, the standard Next.js convention (and what @clerk/nextjs uses) is NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY. This forces developers to pass both env vars explicitly when running tests.
Environment
@clerk/testing: 1.13.36@clerk/nextjs: latest@playwright/test: 1.57.0- Next.js: 15.4.11
Reproduction
- Configure a Next.js app with Clerk using
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEYin.env.local(standard setup) - Set up Playwright with
@clerk/testing - Run tests without explicitly setting
CLERK_PUBLISHABLE_KEY clerkSetup()fails because it only looks forCLERK_PUBLISHABLE_KEY
Workaround
Must pass both env vars when running tests:
CLERK_PUBLISHABLE_KEY=$NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY \
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_xxx \
npx playwright test
Expected Behavior
clerkSetup() should fall back to NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY if CLERK_PUBLISHABLE_KEY is not set, since that's the standard env var name used in Next.js projects with @clerk/nextjs.
Suggested Fix
In the clerkSetup() initialization:
const publishableKey = process.env.CLERK_PUBLISHABLE_KEY
?? process.env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY;
Hi! @clerk/testing is framework agnostic. It works with any SDK, each with their own env var prefix (NEXT_PUBLIC_, PUBLIC_, VITE_, NUXT_PUBLIC_, etc.). Adding a fallback for NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY would either special-case Next.js or require us to maintain an ever-growing list of framework-specific prefixes, neither of which is a good fit for a generic testing package.
The intended approach is to pass the publishable key explicitly via clerkSetup() if the variable is not CLERK_PUBLISHABLE_KEY