Skip to content

chore(repo,testing): Add API keys component e2e tests #6192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 25, 2025

Conversation

wobsoriano
Copy link
Member

@wobsoriano wobsoriano commented Jun 25, 2025

Description

This PR adds integration tests to the <APIKeys /> component

Resolves USER-2238

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • New Features
    • Added a dedicated page for managing API keys in the application interface.
  • Tests
    • Introduced automated tests covering API key creation, revocation, copying, and secret visibility toggling to ensure robust functionality.
  • Chores
    • Added new testing helpers for API key components.

Copy link

changeset-bot bot commented Jun 25, 2025

🦋 Changeset detected

Latest commit: 45f8084

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clerk/testing Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jun 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 25, 2025 9:03pm

Copy link
Contributor

coderabbitai bot commented Jun 25, 2025

📝 Walkthrough

"""

Walkthrough

This change introduces integration tests for the API keys component, specifically targeting its creation, revocation, and copying functionalities. A new Playwright page object is added to facilitate UI interactions with the API keys component, and this page object is registered in the central page objects factory. A new React page is created to render the APIKeys component within a Next.js app template. Additionally, a changeset documents the introduction of API keys testing helpers in the @clerk/testing package.

Assessment against linked issues

Objective Addressed Explanation
Add integration tests for API keys component (USER-2238)
Provide Playwright page object helpers for API keys UI (USER-2238)
Integrate API keys page object in central factory (USER-2238)
Add documentation/changeset for new testing helpers (USER-2238)

Suggested labels

clerk-js

Suggested reviewers

  • dstaley
  • aeliox
    """

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between be7ca1b and 45f8084.

📒 Files selected for processing (1)
  • integration/tests/machine-auth/component.test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
`**/*.{js,ts,tsx,jsx}`: All code must pass ESLint checks with the project's configuration. Use Prettier for consistent code formatting.

**/*.{js,ts,tsx,jsx}: All code must pass ESLint checks with the project's configuration.
Use Prettier for consistent code formatting.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)

List of files the instruction was applied to:

  • integration/tests/machine-auth/component.test.ts
`**/*.{ts,tsx}`: Maintain comprehensive JSDoc comments for public APIs.

**/*.{ts,tsx}: Maintain comprehensive JSDoc comments for public APIs.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)

List of files the instruction was applied to:

  • integration/tests/machine-auth/component.test.ts
`**/*.{test,spec}.{js,ts,tsx,jsx}`: Unit tests are required for all new functionality.

**/*.{test,spec}.{js,ts,tsx,jsx}: Unit tests are required for all new functionality.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)

List of files the instruction was applied to:

  • integration/tests/machine-auth/component.test.ts
`integration/**`: Framework integration templates and E2E tests must be placed in the integration/ directory.

integration/**: Framework integration templates and E2E tests must be placed in the integration/ directory.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/global.mdc)

List of files the instruction was applied to:

  • integration/tests/machine-auth/component.test.ts
`**/*.ts`: Always define explicit return types for functions, especially public ...

**/*.ts: Always define explicit return types for functions, especially public APIs.
Use proper type annotations for variables and parameters where inference isn't clear.
Avoid any type; prefer unknown when type is uncertain, then narrow with type guards.
Use interface for object shapes that might be extended; use type for unions, primitives, and computed types.
Prefer readonly properties for immutable data structures.
Use private for internal implementation details, protected for inheritance, and public explicitly for clarity in public APIs.
Prefer composition and interfaces over deep inheritance chains; use mixins for shared behavior.
Use ES6 imports/exports consistently; avoid barrel files (index.ts re-exports) to prevent circular dependencies.
Use type-only imports (import type { ... }) where possible.
Use as const for literal types and the satisfies operator for type checking without widening.
Enable --incremental and --tsBuildInfoFile for faster builds.
Use ESLint with @typescript-eslint/recommended rules and Prettier for formatting.
Use lint-staged and Husky for pre-commit checks.
Use type-coverage to measure type safety.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/typescript.mdc)

List of files the instruction was applied to:

  • integration/tests/machine-auth/component.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
integration/tests/machine-auth/component.test.ts (4)

1-21: Well-structured test suite setup with proper lifecycle management.

The test configuration, fake user setup, and cleanup logic follow best practices for integration testing.


23-51: Comprehensive API key creation test with good coverage.

The test properly validates creating multiple API keys with different expiration periods and verifies they appear in the table.


94-130: Excellent clipboard testing implementation with proper permission handling.

The test correctly waits for the API response, grants clipboard permissions temporarily, and verifies the copied content matches the secret. The cleanup of permissions is also properly handled.


132-171: Comprehensive visibility toggle test addressing previous feedback.

This test thoroughly validates the secret visibility functionality by checking input type changes and verifying the revealed secret matches the API response. This addresses the question from previous reviews about testing visibility toggling.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

pkg-pr-new bot commented Jun 25, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@6192

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@6192

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@6192

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@6192

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@6192

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@6192

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@6192

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@6192

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@6192

@clerk/express

npm i https://pkg.pr.new/@clerk/express@6192

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@6192

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@6192

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@6192

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@6192

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@6192

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@6192

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@6192

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@6192

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@6192

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@6192

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@6192

@clerk/types

npm i https://pkg.pr.new/@clerk/types@6192

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@6192

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@6192

commit: 45f8084

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (4)
integration/templates/next-app-router/src/app/api-keys/page.tsx (1)

3-5: Consider adding explicit return type for consistency.

The component implementation is clean and follows React best practices. Consider adding an explicit return type for better TypeScript consistency.

-export default function Page() {
+export default function Page(): JSX.Element {
   return <APIKeys />;
 }
packages/testing/src/playwright/unstable/page-objects/apiKeys.ts (2)

4-4: Add explicit return type for the factory function.

Consider adding an explicit return type for better TypeScript documentation and consistency with coding guidelines.

-export const createAPIKeysComponentPageObject = (testArgs: { page: EnhancedPage }) => {
+export const createAPIKeysComponentPageObject = (testArgs: { page: EnhancedPage }): ReturnType<typeof createAPIKeysComponentPageObject> => {

Alternatively, define an interface for the returned object type for better maintainability.


20-22: Consider using more semantic selectors for better test reliability.

CSS class selectors like .cl-apiKeys-root can be brittle if styling changes. Consider using data-testid attributes or role-based selectors where possible for more stable tests.

 waitForMounted: () => {
-  return page.waitForSelector('.cl-apiKeys-root', { state: 'attached' });
+  return page.waitForSelector('[data-testid="api-keys-root"]', { state: 'attached' });
 },

This applies to other CSS class selectors throughout the file as well.

integration/tests/machine-auth/component.test.ts (1)

125-127: Consider adding error handling for clipboard operations.

Clipboard operations can sometimes fail due to browser security policies or timing issues. Consider wrapping the clipboard read in a try-catch or adding retry logic.

-const clipboardText = await page.evaluate('navigator.clipboard.readText()');
-expect(clipboardText).toBe(data.secret);
+try {
+  const clipboardText = await page.evaluate('navigator.clipboard.readText()');
+  expect(clipboardText).toBe(data.secret);
+} catch (error) {
+  throw new Error(`Failed to read clipboard: ${error.message}`);
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d8f2b5c and b07a364.

📒 Files selected for processing (5)
  • integration/playwright.config.ts (1 hunks)
  • integration/templates/next-app-router/src/app/api-keys/page.tsx (1 hunks)
  • integration/tests/machine-auth/component.test.ts (1 hunks)
  • packages/testing/src/playwright/unstable/page-objects/apiKeys.ts (1 hunks)
  • packages/testing/src/playwright/unstable/page-objects/index.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
`**/*.{js,ts,tsx,jsx}`: All code must pass ESLint checks with the project's configuration. Use Prettier for consistent code formatting.

**/*.{js,ts,tsx,jsx}: All code must pass ESLint checks with the project's configuration.
Use Prettier for consistent code formatting.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)

List of files the instruction was applied to:

  • packages/testing/src/playwright/unstable/page-objects/index.ts
  • integration/templates/next-app-router/src/app/api-keys/page.tsx
  • packages/testing/src/playwright/unstable/page-objects/apiKeys.ts
  • integration/playwright.config.ts
  • integration/tests/machine-auth/component.test.ts
`**/*.{ts,tsx}`: Maintain comprehensive JSDoc comments for public APIs.

**/*.{ts,tsx}: Maintain comprehensive JSDoc comments for public APIs.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)

List of files the instruction was applied to:

  • packages/testing/src/playwright/unstable/page-objects/index.ts
  • integration/templates/next-app-router/src/app/api-keys/page.tsx
  • packages/testing/src/playwright/unstable/page-objects/apiKeys.ts
  • integration/playwright.config.ts
  • integration/tests/machine-auth/component.test.ts
`packages/**`: All publishable packages under the @clerk namespace must be located in the packages/ directory.

packages/**: All publishable packages under the @clerk namespace must be located in the packages/ directory.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/global.mdc)

List of files the instruction was applied to:

  • packages/testing/src/playwright/unstable/page-objects/index.ts
  • packages/testing/src/playwright/unstable/page-objects/apiKeys.ts
`**/index.ts`: Use index.ts files for clean imports but avoid deep barrel exports.

**/index.ts: Use index.ts files for clean imports but avoid deep barrel exports.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/react.mdc)

List of files the instruction was applied to:

  • packages/testing/src/playwright/unstable/page-objects/index.ts
`**/*.ts`: Always define explicit return types for functions, especially public ...

**/*.ts: Always define explicit return types for functions, especially public APIs.
Use proper type annotations for variables and parameters where inference isn't clear.
Avoid any type; prefer unknown when type is uncertain, then narrow with type guards.
Use interface for object shapes that might be extended; use type for unions, primitives, and computed types.
Prefer readonly properties for immutable data structures.
Use private for internal implementation details, protected for inheritance, and public explicitly for clarity in public APIs.
Prefer composition and interfaces over deep inheritance chains; use mixins for shared behavior.
Use ES6 imports/exports consistently; avoid barrel files (index.ts re-exports) to prevent circular dependencies.
Use type-only imports (import type { ... }) where possible.
Use as const for literal types and the satisfies operator for type checking without widening.
Enable --incremental and --tsBuildInfoFile for faster builds.
Use ESLint with @typescript-eslint/recommended rules and Prettier for formatting.
Use lint-staged and Husky for pre-commit checks.
Use type-coverage to measure type safety.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/typescript.mdc)

List of files the instruction was applied to:

  • packages/testing/src/playwright/unstable/page-objects/index.ts
  • packages/testing/src/playwright/unstable/page-objects/apiKeys.ts
  • integration/playwright.config.ts
  • integration/tests/machine-auth/component.test.ts
`integration/**`: Framework integration templates and E2E tests must be placed in the integration/ directory.

integration/**: Framework integration templates and E2E tests must be placed in the integration/ directory.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/global.mdc)

List of files the instruction was applied to:

  • integration/templates/next-app-router/src/app/api-keys/page.tsx
  • integration/playwright.config.ts
  • integration/tests/machine-auth/component.test.ts
`**/*.{jsx,tsx}`: Always use functional components with hooks instead of class c...

**/*.{jsx,tsx}: Always use functional components with hooks instead of class components.
Follow PascalCase naming for components; the filename and component name should match.
Limit component size to 150-200 lines; extract logic into custom hooks.
Export components as named exports for better tree-shaking.
One component per file with matching filename and component name.
Co-locate related files (component, test, stories) in the same directory.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/react.mdc)

List of files the instruction was applied to:

  • integration/templates/next-app-router/src/app/api-keys/page.tsx
`**/*.{test,spec}.{js,ts,tsx,jsx}`: Unit tests are required for all new functionality.

**/*.{test,spec}.{js,ts,tsx,jsx}: Unit tests are required for all new functionality.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)

List of files the instruction was applied to:

  • integration/tests/machine-auth/component.test.ts
🧬 Code Graph Analysis (1)
packages/testing/src/playwright/unstable/page-objects/index.ts (1)
packages/testing/src/playwright/unstable/page-objects/apiKeys.ts (1)
  • createAPIKeysComponentPageObject (4-59)
⏰ Context from checks skipped due to timeout of 90000ms (24)
  • GitHub Check: Integration Tests (nextjs, chrome, 14)
  • GitHub Check: Integration Tests (nextjs, chrome, 15)
  • GitHub Check: Integration Tests (nextjs, chrome, 13)
  • GitHub Check: Integration Tests (billing, chrome)
  • GitHub Check: Integration Tests (nuxt, chrome)
  • GitHub Check: Integration Tests (react-router, chrome)
  • GitHub Check: Integration Tests (vue, chrome)
  • GitHub Check: Integration Tests (tanstack-react-start, chrome)
  • GitHub Check: Integration Tests (tanstack-react-router, chrome)
  • GitHub Check: Integration Tests (expo-web, chrome)
  • GitHub Check: Integration Tests (astro, chrome)
  • GitHub Check: Integration Tests (localhost, chrome)
  • GitHub Check: Integration Tests (ap-flows, chrome)
  • GitHub Check: Integration Tests (sessions, chrome)
  • GitHub Check: Integration Tests (elements, chrome)
  • GitHub Check: Integration Tests (express, chrome)
  • GitHub Check: Integration Tests (quickstart, chrome)
  • GitHub Check: Integration Tests (generic, chrome)
  • GitHub Check: Unit Tests (22, **)
  • GitHub Check: Publish with pkg-pr-new
  • GitHub Check: Static analysis
  • GitHub Check: Unit Tests (18, --filter=@clerk/astro --filter=@clerk/backend --filter=@clerk/express --filter=@c...
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (8)
integration/playwright.config.ts (1)

23-23: LGTM: Necessary permission for clipboard testing.

The addition of clipboard-read permission properly enables the API key copying tests to verify clipboard functionality.

packages/testing/src/playwright/unstable/page-objects/index.ts (2)

3-3: LGTM: Proper integration following established patterns.

The import follows the existing alphabetical ordering and naming conventions.


50-50: LGTM: Consistent page object registration.

The apiKeys page object is properly integrated using the same pattern as other page objects.

packages/testing/src/playwright/unstable/page-objects/apiKeys.ts (2)

44-47: Verify async/await pattern in selectExpiration method.

The method properly handles the asynchronous dropdown interaction pattern. The implementation correctly waits for the dropdown to open before selecting an option.


7-16: Well-structured expiration options mapping.

The expirationOptions constant with as const assertion provides good type safety and maintains the mapping between internal values and UI display text.

integration/tests/machine-auth/component.test.ts (3)

7-8: LGTM: Proper test configuration for stateful API key tests.

Using serial mode is appropriate here since the tests likely depend on the state of created API keys. The environment configuration targeting API keys is also correct.


12-21: LGTM: Proper test lifecycle management.

The setup and teardown properly handle fake user creation and cleanup, ensuring test isolation at the suite level.


114-127: LGTM: Well-implemented clipboard verification test.

The test properly:

  • Intercepts the API response to get the expected secret
  • Triggers the copy action
  • Reads from clipboard using the configured permission
  • Verifies the clipboard content matches the API response

This is a comprehensive integration test that validates the entire copy flow.

wobsoriano and others added 3 commits June 25, 2025 12:55
@wobsoriano wobsoriano changed the title chore(repo): Add API keys component e2e tests chore(repo,testing): Add API keys component e2e tests Jun 25, 2025
Copy link
Member

@alexcarpenter alexcarpenter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

await expect(table.locator('.cl-tableRow', { hasText: apiKeyName })).toHaveCount(0);
});

test('can copy api keys', async ({ page, context }) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also test toggling visiblity?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, added!

@wobsoriano wobsoriano enabled auto-merge (squash) June 25, 2025 21:12
@wobsoriano wobsoriano merged commit 6200c5e into main Jun 25, 2025
63 of 64 checks passed
@wobsoriano wobsoriano deleted the rob/user-2238-api-keys-e2e branch June 25, 2025 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants