Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(testing): Introduce support for the Cypress framework #3378

Merged
merged 5 commits into from
May 15, 2024

Conversation

anagstef
Copy link
Member

Description

This PR adds support for the Cypress framework. It's been tested on the latest version of Cypress (v13).

All utilities related to Cypress are exported from the subpath @clerk/testing/cypress.

Also, this PR adds an Error to be thrown if someone tries to import from the package's root path (@clerk/testing).

Usage

Firstly, add your Clerk keys (CLERK_PUBLISHABLE_KEY and CLERK_SECRET_KEY) to your environment variables file (e.g. .env.local or .env.).
You can find these keys in your Clerk Dashboard.

All Cypress related utilities are exported from @clerk/testing/cypress. Make sure that your import paths are correct!

On your cypress.config.ts, you must use the clerkSetup function to set up Clerk for your tests.
Keep in mind that you must pass the Cypress config object to the clerkSetup function and also return the new config object from the setupNodeEvents function.

// cypress.config.ts
import { clerkSetup } from '@clerk/testing/cypress';
import { defineConfig } from 'cypress';

export default defineConfig({
  e2e: {
    setupNodeEvents(on, config) {
      return clerkSetup({ config });
    },
    baseUrl: 'http://localhost:3000', // or your app's URL
  },
});

Then, you can use the setupClerkTestingToken function to bypass bot protection on your tests.

// cypress/e2e/app.cy.ts
import { setupClerkTestingToken } from "@clerk/testing/cypress";

it("sign up", () => {
  setupClerkTestingToken();

  cy.visit('/sign-up');
  ...
});

Checklist

  • npm test runs as expected.
  • npm run 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:

Copy link

changeset-bot bot commented May 14, 2024

馃 Changeset detected

Latest commit: 80a6440

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

@anagstef
Copy link
Member Author

!snapshot

@clerk-cookie
Copy link
Collaborator

Hey @anagstef - the snapshot version command generated the following package versions:

Package Version
gatsby-plugin-clerk 5.0.0-beta.45
@clerk/testing 1.1.0-snapshot.v641a910

Tip: Use the snippet copy button below to quickly install the required packages.
gatsby-plugin-clerk

npm i gatsby-plugin-clerk@5.0.0-beta.45 --save-exact

@clerk/testing

npm i @clerk/testing@1.1.0-snapshot.v641a910 --save-exact

packages/testing/README.md Outdated Show resolved Hide resolved
packages/testing/README.md Outdated Show resolved Hide resolved
packages/testing/README.md Outdated Show resolved Hide resolved
@nikosdouvlis nikosdouvlis merged commit 37d2470 into main May 15, 2024
10 checks passed
@nikosdouvlis nikosdouvlis deleted the stefanos/core-2003-support-cypress branch May 15, 2024 10:46
@clerk-cookie clerk-cookie mentioned this pull request May 15, 2024
frankdavidcorona pushed a commit to frankdavidcorona/javascript that referenced this pull request May 15, 2024
* feat(testing): Introduce support for the Cypress framework

* chore(testing): Update README

* chore(testing): Fix typos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants