clerk-testing

作成者: clerk

Clerk認証フローのE2Eテストユーティリティ(PlaywrightおよびCypress対応)。PlaywrightとCypressの両フレームワークをサポートし、フレームワーク固有のセットアップパターン(PlaywrightではglobalSetup、Cypressではカスタムコマンド)を提供。clerkSetup()とsetupClerkTestingToken()ユーティリティを使用してテスト環境を初期化し、ボット検出をバイパス。認証済みセッションをテスト間で再利用するstorageState永続化機能を含み、テスト実行時間を短縮。テスト用APIキー(pk_test_*、...)が必要。

npx skills add https://github.com/clerk/skills --skill clerk-testing

Testing

Decision Tree

FrameworkDocumentation
Overviewhttps://clerk.com/docs/guides/development/testing/overview
Playwrighthttps://clerk.com/docs/guides/development/testing/playwright/overview
Cypresshttps://clerk.com/docs/guides/development/testing/cypress/overview

Mental Model

Test auth = isolated session state. Each test needs fresh auth context.

  • clerkSetup() initializes test environment
  • setupClerkTestingToken() bypasses bot detection
  • storageState persists auth between tests for speed

Workflow

  1. Identify test framework (Playwright or Cypress)
  2. WebFetch the appropriate URL from decision tree above
  3. Follow official setup instructions
  4. Use pk_test_* and sk_test_* keys only

Best Practices

  • Use setupClerkTestingToken() before navigating to auth pages
  • Use test API keys: pk_test_xxx, sk_test_xxx
  • Save auth state with storageState for faster tests
  • Use page.waitForSelector('[data-clerk-component]') for Clerk UI

Anti-Patterns

PatternProblemFix
Production keys in testsSecurity riskUse pk_test_* keys
No setupClerkTestingToken()Auth failsCall before navigation
UI-based sign-in every testSlow testsUse storageState

Framework-Specific

Playwright: Use globalSetup for auth state Cypress: Add addClerkCommands({ Cypress, cy }) to support file

See Also

  • clerk-setup - Install Clerk before adding tests
  • clerk-nextjs-patterns - Next.js patterns being tested
  • Demo Repo

clerkのその他のスキル

clerk-monorepo
clerk
clerk/javascript SDKモノレポ内で効率的に作業する。リポジトリのセットアップ、パッケージのビルド/テスト/実行、@clerk/*のうちどれを使うかの決定の際に使用する…
official
mosaic
clerk
Work on Mosaic UI: styling a component with slot recipes (`defineSlotRecipe` / `useRecipe` / slots / variants), or building a flow — authoring a state machine…
official
mosaic-machine
clerk
Mosaicステートマシンの作成と使用を行います。ユーザーがcreateMachineでステートマシンを記述しているとき、マルチステップフローをモデリングしているとき、マシンをReactに接続しているときなどに使用します。
official
clerk-android
clerk
Implement Clerk authentication for native Android apps using Kotlin and Jetpack Compose with clerk-android source-guided patterns. Use for prebuilt…
official
clerk-astro-patterns
clerk
Clerkを使ったAstroパターン — ミドルウェア、SSRページ、アイランドコンポーネント、APIルート、静的レンダリングとSSRレンダリング。トリガー条件: astro clerk、clerk astro middleware、…
official
clerk-backend-api
clerk
Clerk バックエンド REST API の探索および実行ツール。タグを参照し、エンドポイントスキーマを確認し、認証済みリクエストを実行します。ユーザーの一覧取得や管理の際に使用…
official
clerk-chrome-extension-patterns
clerk
@clerk/chrome-extensionによるChrome拡張機能の認証 -- popup/sidepanelのセットアップ、Webアプリ経由のOAuth/SAML用syncHost、Service Worker用のcreateClerkClient、および…
official
clerk-cli
clerk
Operate the Clerk CLI (`clerk` binary) for authentication, user/org/session management, impersonation, local webhook testing, deploy verification, instance…
official