1+ import { expect } from "bun:test" ;
12import { mkdtemp , cp , rm , realpath } from "node:fs/promises" ;
23import { join } from "node:path" ;
34import { tmpdir } from "node:os" ;
@@ -25,19 +26,6 @@ function requireEnv(name: string): string {
2526 return val ;
2627}
2728
28- /** Build a shared env object for CLI commands. Requires CLERK_PLATFORM_API_KEY. */
29- function clerkEnv ( configDir ?: string ) : Record < string , string | undefined > {
30- if ( ! process . env . CLERK_PLATFORM_API_KEY ) {
31- throw new Error (
32- "Missing required env var: set CLERK_PLATFORM_API_KEY before running e2e tests." ,
33- ) ;
34- }
35- return {
36- ...process . env ,
37- ...( configDir ? { CLERK_CONFIG_DIR : configDir } : { } ) ,
38- } ;
39- }
40-
4129/** Throw with a descriptive message if a shell command failed. */
4230function assertSuccess (
4331 label : string ,
@@ -62,10 +50,14 @@ async function copyFixture(fixtureDir: string, projectDir: string): Promise<void
6250 */
6351async function linkProject ( projectDir : string , configDir : string ) : Promise < void > {
6452 const appId = requireEnv ( "CLERK_CLI_TEST_APP_ID" ) ;
53+ const platformAPIKey = requireEnv ( "CLERK_PLATFORM_API_KEY" ) ;
6554
6655 const result = await Bun . $ `bun ${ CLI_PATH } --mode human link --app ${ appId } `
6756 . cwd ( projectDir )
68- . env ( clerkEnv ( configDir ) )
57+ . env ( {
58+ CLERK_CONFIG_DIR : configDir ,
59+ CLERK_PLATFORM_API_KEY : platformAPIKey ,
60+ } )
6961 . quiet ( )
7062 . nothrow ( ) ;
7163
@@ -95,9 +87,14 @@ async function gitInit(projectDir: string): Promise<void> {
9587 * with skill template files that break framework typecheck.
9688 */
9789async function runClerkInit ( projectDir : string , configDir : string ) : Promise < void > {
90+ const platformAPIKey = requireEnv ( "CLERK_PLATFORM_API_KEY" ) ;
91+
9892 const result = await Bun . $ `bun ${ CLI_PATH } --mode human init --yes --no-skills`
9993 . cwd ( projectDir )
100- . env ( clerkEnv ( configDir ) )
94+ . env ( {
95+ CLERK_CONFIG_DIR : configDir ,
96+ CLERK_PLATFORM_API_KEY : platformAPIKey ,
97+ } )
10198 . quiet ( )
10299 . nothrow ( ) ;
103100
@@ -168,16 +165,14 @@ export async function setupFixture(name: FixtureName): Promise<Fixture> {
168165
169166 // Verify clerk init wrote env files and extract keys.
170167 const envVars = await parseEnvFiles ( projectDir ) ;
168+
171169 const publishableKeyName = await detectPublishableKeyName ( projectDir ) ;
172170 publishableKey = envVars [ publishableKeyName ] ?? "" ;
173- if ( ! publishableKey ) {
174- throw new Error ( `${ publishableKeyName } not found in env files written by clerk init.` ) ;
175- }
171+ expect ( publishableKey ) . toMatch ( / ^ p k _ ( t e s t | l i v e ) _ [ a - z 0 - 9 ] + $ / ) ;
172+
176173 const secretKeyName = await detectSecretKeyName ( projectDir ) ;
177174 secretKey = envVars [ secretKeyName ] ?? "" ;
178- if ( ! secretKey ) {
179- throw new Error ( `${ secretKeyName } not found in env files written by clerk init.` ) ;
180- }
175+ expect ( secretKey ) . toMatch ( / ^ s k _ ( t e s t | l i v e ) _ [ a - z 0 - 9 ] + $ / ) ;
181176
182177 const install = await Bun . $ `npm ci --ignore-scripts --legacy-peer-deps`
183178 . cwd ( projectDir )
0 commit comments