Skip to content

Commit

Permalink
Merge branch 'main' into rob/eco-302-move-environment-variable-logic-…
Browse files Browse the repository at this point in the history
…into-clerkshared
  • Loading branch information
wobsoriano authored Feb 4, 2025
2 parents db1427e + 1f8ebfb commit 01ba102
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
6 changes: 6 additions & 0 deletions packages/testing/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @clerk/testing

## 1.4.20

### Patch Changes

- Fix captcha triggering on Playwright tests ([#5075](https://github.com/clerk/javascript/pull/5075)) by [@anagstef](https://github.com/anagstef)

## 1.4.19

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/testing/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@clerk/testing",
"version": "1.4.19",
"version": "1.4.20",
"description": "Utilities to help you create E2E test suites for apps using Clerk",
"keywords": [
"auth",
Expand Down
35 changes: 30 additions & 5 deletions packages/testing/src/playwright/setupClerkTestingToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,41 @@ export const setupClerkTestingToken = async ({ page, options }: SetupClerkTestin
}
const apiUrl = `https://${fapiUrl}/v1/**/*`;

await page.route(apiUrl, (route, request) => {
const originalUrl = new URL(request.url());
await page.route(apiUrl, async route => {
const originalUrl = new URL(route.request().url());
const testingToken = process.env.CLERK_TESTING_TOKEN;

if (testingToken) {
originalUrl.searchParams.set(TESTING_TOKEN_PARAM, testingToken);
}

void route.continue({
url: originalUrl.toString(),
});
try {
const response = await route.fetch({
url: originalUrl.toString(),
});

const json = await response.json();

// Override captcha_bypass in /v1/client
if (json?.response?.captcha_bypass === false) {
json.response.captcha_bypass = true;
}

// Override captcha_bypass in piggybacking
if (json?.client?.captcha_bypass === false) {
json.client.captcha_bypass = true;
}

await route.fulfill({
response,
json,
});
} catch {
await route
.continue({
url: originalUrl.toString(),
})
.catch(console.error);
}
});
};
2 changes: 1 addition & 1 deletion packages/types/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface ClientJSON extends ClerkResourceJSON {
sessions: SessionJSON[];
sign_up: SignUpJSON | null;
sign_in: SignInJSON | null;
captcha_bypass?: boolean;
captcha_bypass?: boolean; // this is used by the @clerk/testing package
last_active_session_id: string | null;
cookie_expires_at: number | null;
created_at: number;
Expand Down

0 comments on commit 01ba102

Please sign in to comment.