Test E2E avec Clerk - authentification programmatique

VérifiéSûr

Connectez des utilisateurs Clerk programmatiquement pour vos tests e2e sans interagir avec l'interface Clerk. Compatible avec le support Clerk de Replit.

Spar Skills Guide Bot
TestingIntermédiaire
1030/08/2026
Claude Code
#clerk#e2e-testing#authentication#playwright#replit

Recommandé pour

Notre avis

Cette compétence permet de connecter programmatiquement des utilisateurs Clerk pour des tests e2e, sans interagir avec l'interface de Clerk.

Points forts

  • Évite l'interaction avec l'UI Clerk et accélère les tests
  • Prend en charge les scénarios multi-utilisateurs avec des contextes navigateur séparés
  • Permet de configurer la durée de vie de session et le chemin de redirection

Limites

  • Fonctionne uniquement avec les applications Replit utilisant le support Clerk
  • Requiert l'utilisation de la fonction spécifique signInClerkUser
  • La session est liée au contexte navigateur qui accède à l'URL de connexion
Quand l'utiliser

Quand vous testez de bout en bout une application authentifiée par Clerk et que vous devez connecter des utilisateurs de test sans passer par l'interface.

Quand l'éviter

Quand l'application n'utilise pas Clerk ou n'est pas déployée sur Replit, ou si vous devez tester le flux UI de connexion lui-même.

Analyse de sécurité

Sûr
Score qualité90/100

The skill provides instructions for programmatic Clerk sign-in during e2e testing using a provided function. It does not include destructive commands, exfiltration, obfuscated payloads, or attempts to disable safety mechanisms. The use of authentication APIs is for legitimate testing purposes.

Aucun point d'attention détecté

Exemples

Sign in a single test user
Use signInClerkUser to sign in testuser@example.com (firstName Test, lastName User) and navigate the page to the returned sign-in URL.
Sign in multiple users in separate contexts
Sign in two different Clerk users in separate browser contexts and verify each user sees only their own data.
Sign in with a redirect base path
Sign in a Clerk user with basePath '/my-app/' to test an artifact in a pnpm workspace, then navigate to the returned sign-in URL.

name: clerk-auth-e2e-testing-only description: Programmatic Clerk sign-in for e2e testing. Use when the application authenticates with Clerk and you need to sign in test users (including multi-user scenarios) without interacting with the Clerk UI. Note this only works for applications built with Replit's Clerk Authentication support.

Clerk Auth E2E Testing Only

Sign in Clerk users programmatically for e2e tests. Use the signInClerkUser function only — do not interact with the Clerk UI directly.

Available Functions (from ExecutePlaywrightAction)

async function signInClerkUser(
  signInOptions: {
    firstName: string;
    lastName?: string;
    email: string;
    ttl?: number; // TTL in seconds (default: 3600)
    basePath?: string; // Relative URL path appended to the dev domain for the post-sign-in redirect
  }
): Promise<string>

This function is in scope of the code for ExecutePlaywrightAction and can be used directly without any registration.

It returns a sign-in URL; navigate a page to that URL to inject the sign-in session.

Usage

Sign in a single user

const signInUrl = await signInClerkUser({
  firstName: "Test",
  lastName: "User",
  email: "testuser@example.com",
});
// Navigate to the returned sign-in URL to inject the sign-in session.
await page.goto(signInUrl);

Sign in for an artifact in a pnpm workspace

When testing an artifact served under its own preview path (e.g. in a multi-artifact or pnpm workspace repl), set basePath to the artifact's preview URL so the sign-in session redirects to the correct artifact.

// Set basePath to the artifact's preview path so Clerk redirects there after sign-in
const signInUrl = await signInClerkUser({
  firstName: "Test",
  lastName: "User",
  email: "testuser@example.com",
  basePath: "/my-app/",
});
await page.goto(signInUrl);

Sign in multiple users in independent browser contexts

const context = await newBrowserContext({ /* context options */ });
context.setDefaultTimeout(3000);
const newPage = await context.newPage();
const signInUrl = await signInClerkUser({
  firstName: "Bob",
  lastName: "Test",
  email: "bobtest@example.com",
});
await newPage.goto(signInUrl);

Test Plan Examples

  • [Clerk] Sign in admin@example.com programmatically and navigate to the returned sign-in URL
  • [Browser] Verify the admin dashboard appears
  • [Clerk] Sign in a second user in a new browser context
  • [Browser] Verify both users see their own data

Notes

  • Sessions are scoped to the browser context whose page navigates to the sign-in URL
  • Do not interact with the Clerk UI (sign-in forms, modals) — only use signInClerkUser
  • The default session TTL is 3600 seconds; pass ttl to change it
Skills similaires