Skip to content

Commit 72e025a

Browse files
committed
fix(e2e): propagate CLERK_FAPI and CLERK_TESTING_TOKEN to adopting workers
Workers that adopt a running app from the state file were missing CLERK_FAPI and CLERK_TESTING_TOKEN env vars because clerkSetup() only runs in the worker that acquires the lock. Store the tokens in the state file and set them in process.env when adopting.
1 parent 50a5db7 commit 72e025a

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

integration/models/longRunningApplication.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ export const longRunningApplication = (params: LongRunningApplicationParams) =>
8585
pid = data.pid;
8686
appDir = data.appDir;
8787
env = params.env;
88+
// Propagate testing tokens to this worker process so that
89+
// setupClerkTestingToken() can bypass bot protection.
90+
if (data.clerkFapi) {
91+
process.env.CLERK_FAPI = data.clerkFapi;
92+
}
93+
if (data.clerkTestingToken) {
94+
process.env.CLERK_TESTING_TOKEN = data.clerkTestingToken;
95+
}
8896
return true;
8997
}
9098
return false;
@@ -171,7 +179,16 @@ export const longRunningApplication = (params: LongRunningApplicationParams) =>
171179
pid = serveResult.pid;
172180
appDir = app.appDir;
173181
log(`Serve complete: port=${port}, serverUrl=${serverUrl}, pid=${pid}`);
174-
stateFile.addLongRunningApp({ port, serverUrl, pid, id, appDir, env: params.env.toJson() });
182+
stateFile.addLongRunningApp({
183+
port,
184+
serverUrl,
185+
pid,
186+
id,
187+
appDir,
188+
env: params.env.toJson(),
189+
clerkFapi: process.env.CLERK_FAPI,
190+
clerkTestingToken: process.env.CLERK_TESTING_TOKEN,
191+
});
175192
} catch (error) {
176193
console.error('Error during app serve:', error);
177194
throw error;

integration/models/stateFile.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export type AppParams = {
99
pid?: number;
1010
appDir: string;
1111
env: ReturnType<EnvironmentConfig['toJson']>;
12+
clerkFapi?: string;
13+
clerkTestingToken?: string;
1214
};
1315

1416
type StandaloneAppParams = {

0 commit comments

Comments
 (0)