Skip to content

@clerk/testing: signIn() times out with concurrent Playwright workers (--workers=2+) #7891

@joerizz23

Description

@joerizz23

Description

When using @clerk/testing with Playwright and --workers=2 (or more), all tests fail with TimeoutError: page.waitForFunction: Timeout 15000ms exceeded at clerk.signIn(). With --workers=1, authentication works 100% reliably.

Environment

  • @clerk/testing: 1.13.36
  • @clerk/nextjs: latest
  • @playwright/test: 1.57.0
  • Next.js: 15.4.11
  • OS: Windows 11 (also likely affects Linux/macOS)
  • Auth strategy: emailAddress

Reproduction

  1. Set up a Next.js app with Clerk authentication
  2. Create a Playwright fixture using @clerk/testing:
import { clerkSetup, clerk } from "@clerk/testing/playwright";

// In fixture:
await clerk.signIn({
  page,
  emailAddress: testUser.email,
});
  1. Run tests with --workers=1all tests pass
  2. Run tests with --workers=2all tests fail

Error

TimeoutError: page.waitForFunction: Timeout 15000ms exceeded.

  at loaded (node_modules/@clerk/testing/src/playwright/helpers.ts:100:14)
  at Object.b (node_modules/@clerk/testing/src/playwright/helpers.ts:120:9)

The timeout occurs at the window.Clerk?.loaded === true && window.Clerk?.user !== null wait inside signIn().

Analysis

Each Playwright worker creates a separate browser instance. When 2+ workers call clerk.signIn() concurrently:

  • setupClerkTestingToken() injects the dev-browser token into each browser
  • Both browsers navigate and wait for window.Clerk.loaded && window.Clerk.user
  • The wait times out on both workers

Possible causes:

  1. Clerk Backend API rate-limits concurrent testing token validations from the same publishable key
  2. ClerkJS client-side hydration conflicts between concurrent browser sessions
  3. The dev-browser token mechanism doesn't support multiple simultaneous sessions

Expected Behavior

@clerk/testing should support concurrent Playwright workers, or the documentation should explicitly state that --workers=1 is required.

Suggested Improvements

  • Support parallel test users with isolated Clerk sessions
  • Provide a testing mode that doesn't require live ClerkJS hydration (e.g., a static token that bypasses the window.Clerk.loaded wait)
  • Document the --workers=1 limitation if concurrent sessions aren't supported

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions