-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from clerk/use-clerk-testing-tokens
Use `@clerk/testing` package to generate and use testing tokens
- Loading branch information
Showing
28 changed files
with
2,253 additions
and
1,910 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key | ||
CLERK_SECRET_KEY=your_clerk_secret_key | ||
CLERK_SECRET_KEY=your_clerk_secret_key | ||
|
||
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in | ||
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { clerkSetup } from "@clerk/testing/cypress"; | ||
import { defineConfig } from "cypress"; | ||
|
||
export default defineConfig({ | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
return clerkSetup({ config }); | ||
}, | ||
baseUrl: "http://localhost:3000", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"test_email": "your_clerk_test_email", | ||
"test_password": "your_clerk_test_password" | ||
"test_user": "user", | ||
"test_password": "password" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* eslint-disable */ | ||
// Disable ESLint to prevent failing linting inside the Next.js repo. | ||
// If you're using ESLint on your project, we recommend installing the ESLint Cypress plugin instead: | ||
// https://github.com/cypress-io/eslint-plugin-cypress | ||
import { setupClerkTestingToken } from "@clerk/testing/cypress"; | ||
|
||
// Cypress E2E Test | ||
describe("Testing Tokens", () => { | ||
it("sign in", () => { | ||
setupClerkTestingToken(); | ||
|
||
cy.visit('/protected'); | ||
|
||
cy.contains('h1', 'Sign in'); | ||
cy.get('.cl-signIn-root').should('exist'); | ||
cy.get('input[name=identifier]').type(Cypress.env('test_user')); | ||
|
||
cy.get('.cl-formButtonPrimary').contains('button', 'Continue').click(); | ||
cy.get('input[name=password]').type(Cypress.env('test_password')); | ||
|
||
|
||
cy.get('.cl-formButtonPrimary').contains('button', 'Continue').click(); | ||
|
||
|
||
cy.url().should('include', '/protected'); | ||
cy.contains('h1', 'This is a PROTECTED page'); | ||
|
||
cy.visit('/'); | ||
cy.contains('signed-in'); | ||
|
||
}); | ||
|
||
// Account Portal example | ||
// it("sign in with Account Portal redirects", () => { | ||
// setupClerkTestingToken(); | ||
|
||
// cy.origin('https://relieved-chamois-53.accounts.dev', () => { | ||
// cy.visit('http://localhost:3000/protected'); | ||
|
||
// cy.contains('h1', 'Sign in'); | ||
// cy.get('.cl-signIn-root').should('exist'); | ||
// cy.get('input[name=identifier]').type(Cypress.env('test_user')); | ||
|
||
// cy.get('.cl-formButtonPrimary').contains('button', 'Continue').click(); | ||
// cy.get('input[name=password]').type(Cypress.env('test_password')); | ||
|
||
|
||
// cy.get('.cl-formButtonPrimary').contains('button', 'Continue').click(); | ||
// }); | ||
|
||
// cy.url().should('include', '/protected'); | ||
// cy.contains('h1', 'This is a PROTECTED page'); | ||
|
||
// }); | ||
|
||
it("sign in with command", () => { | ||
setupClerkTestingToken(); | ||
cy.visit(`/`); | ||
cy.signIn(); | ||
cy.visit('/protected'); | ||
cy.contains('h1', 'This is a PROTECTED page'); | ||
}); | ||
|
||
it("sign up", () => { | ||
setupClerkTestingToken(); | ||
|
||
cy.visit('/sign-up'); | ||
cy.contains('h1', 'Sign Up'); | ||
cy.get('.cl-signUp-root').should('exist'); | ||
cy.get('input[name=username]').type('e2euser' + new Date().getTime()); | ||
|
||
cy.get('input[name=password]').type(Cypress.env('test_password')); | ||
|
||
cy.get('.cl-formButtonPrimary').contains('button', 'Continue').click(); | ||
|
||
cy.visit('/protected'); | ||
cy.url().should('include', '/protected'); | ||
}); | ||
}); | ||
|
||
// Prevent TypeScript from reading file as legacy script | ||
export {}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/// <reference types="cypress" /> | ||
import type { Clerk } from '@clerk/types'; | ||
// *********************************************** | ||
// This example commands.ts shows you how to | ||
// create various custom commands and overwrite | ||
// existing commands. | ||
// | ||
// For more comprehensive examples of custom | ||
// commands please read more here: | ||
// https://on.cypress.io/custom-commands | ||
// *********************************************** | ||
// | ||
// | ||
// -- This is a parent command -- | ||
// Cypress.Commands.add('login', (email, password) => { ... }) | ||
// | ||
// | ||
// -- This is a child command -- | ||
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This is a dual command -- | ||
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... }) | ||
// | ||
// | ||
// -- This will overwrite an existing command -- | ||
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... }) | ||
// | ||
declare global { | ||
namespace Cypress { | ||
interface Chainable { | ||
signOut(): Chainable<void> | ||
signIn(): Chainable<void> | ||
} | ||
} | ||
interface Window { | ||
Clerk: Clerk; | ||
} | ||
} | ||
|
||
Cypress.Commands.add(`signOut`, () => { | ||
cy.log(`Sign out by clearing all cookies.`); | ||
cy.clearCookies({ domain: null, }); | ||
}); | ||
|
||
Cypress.Commands.add(`signIn`, () => { | ||
cy.log(`Signing in.`); | ||
|
||
cy.window() | ||
.should((window) => { | ||
expect(window).to.not.have.property(`Clerk`, undefined); | ||
expect(window.Clerk.loaded).to.eq(true); | ||
}) | ||
.then(async (window) => { | ||
const res = await window.Clerk.client.signIn.create({ | ||
identifier: Cypress.env(`test_user`), | ||
password: Cypress.env(`test_password`), | ||
}); | ||
|
||
await window.Clerk.setActive({ | ||
session: res.createdSessionId, | ||
}); | ||
|
||
cy.log(`Finished Signing in.`); | ||
}); | ||
}); | ||
|
||
// Prevent TypeScript from reading file as legacy script | ||
export {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": ["es5", "dom"], | ||
"types": ["cypress", "node", "@clerk/types"] | ||
}, | ||
"include": ["**/*.ts"] | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { clerkMiddleware, createRouteMatcher } from "@clerk/nextjs/server"; | ||
|
||
const isProtectedRoute = createRouteMatcher([ | ||
'/protected(.*)', | ||
]); | ||
|
||
export default clerkMiddleware((auth, req) => { | ||
if (isProtectedRoute(req)) auth().protect(); | ||
}); | ||
|
||
|
||
export const config = { | ||
matcher: ['/((?!.*\\..*|_next).*)', '/', '/(api|trpc)(.*)'], | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.