diff --git a/.changeset/clean-beds-count.md b/.changeset/clean-beds-count.md new file mode 100644 index 00000000000..0f983616d5d --- /dev/null +++ b/.changeset/clean-beds-count.md @@ -0,0 +1,5 @@ +--- +'@clerk/testing': patch +--- + +Improve the error message when `setupClerkTestingToken` cannot find the FAPI URL diff --git a/packages/testing/src/common/errors.ts b/packages/testing/src/common/errors.ts new file mode 100644 index 00000000000..446a262cd87 --- /dev/null +++ b/packages/testing/src/common/errors.ts @@ -0,0 +1,3 @@ +export const ERROR_MISSING_FRONTEND_API_URL = + 'The Clerk Frontend API URL is required to bypass bot protection. ' + + 'Make sure the clerkSetup function is called during your global setup before setupClerkTestingToken is called.'; diff --git a/packages/testing/src/common/index.ts b/packages/testing/src/common/index.ts index b389d93b254..6f410441d93 100644 --- a/packages/testing/src/common/index.ts +++ b/packages/testing/src/common/index.ts @@ -1,3 +1,4 @@ export * from './constants'; export * from './types'; export * from './setup'; +export * from './errors'; diff --git a/packages/testing/src/cypress/setupClerkTestingToken.ts b/packages/testing/src/cypress/setupClerkTestingToken.ts index b2c1e6eb5da..1b38f8188ff 100644 --- a/packages/testing/src/cypress/setupClerkTestingToken.ts +++ b/packages/testing/src/cypress/setupClerkTestingToken.ts @@ -1,6 +1,6 @@ /// import type { SetupClerkTestingTokenOptions } from '../common'; -import { TESTING_TOKEN_PARAM } from '../common'; +import { ERROR_MISSING_FRONTEND_API_URL, TESTING_TOKEN_PARAM } from '../common'; type SetupClerkTestingTokenParams = { options?: SetupClerkTestingTokenOptions; @@ -24,7 +24,7 @@ type SetupClerkTestingTokenParams = { export const setupClerkTestingToken = (params?: SetupClerkTestingTokenParams) => { const fapiUrl = params?.options?.frontendApiUrl || Cypress.env('CLERK_FAPI'); if (!fapiUrl) { - throw new Error('The Frontend API URL is required to bypass bot protection.'); + throw new Error(ERROR_MISSING_FRONTEND_API_URL); } const apiUrl = `https://${fapiUrl}/v1/**`; diff --git a/packages/testing/src/playwright/setupClerkTestingToken.ts b/packages/testing/src/playwright/setupClerkTestingToken.ts index a51bffc4bd9..84d48cd42a8 100644 --- a/packages/testing/src/playwright/setupClerkTestingToken.ts +++ b/packages/testing/src/playwright/setupClerkTestingToken.ts @@ -1,7 +1,7 @@ import type { Page } from '@playwright/test'; import type { SetupClerkTestingTokenOptions } from '../common'; -import { TESTING_TOKEN_PARAM } from '../common'; +import { ERROR_MISSING_FRONTEND_API_URL, TESTING_TOKEN_PARAM } from '../common'; type SetupClerkTestingTokenParams = { page: Page; @@ -27,7 +27,7 @@ type SetupClerkTestingTokenParams = { export const setupClerkTestingToken = async ({ page, options }: SetupClerkTestingTokenParams) => { const fapiUrl = options?.frontendApiUrl || process.env.CLERK_FAPI; if (!fapiUrl) { - throw new Error('The Frontend API URL is required to bypass bot protection.'); + throw new Error(ERROR_MISSING_FRONTEND_API_URL); } const apiUrl = `https://${fapiUrl}/v1/**/*`;