-
Notifications
You must be signed in to change notification settings - Fork 74
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 #1 from brocoders/feat/e2e-test
tests: add Cypress
- Loading branch information
Showing
18 changed files
with
1,772 additions
and
33 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
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,28 @@ | ||
name: E2E Tests | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
cypress-run: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
# Install NPM dependencies, cache them correctly | ||
# and run all Cypress tests | ||
- name: Cypress run | ||
uses: cypress-io/github-action@v6 | ||
with: | ||
build: cp example.env.local .env.local | ||
start: npm run dev | ||
- name: Artifacts | ||
uses: actions/upload-artifact@v3 | ||
if: failure() | ||
with: | ||
name: cypress-screenshots | ||
path: cypress/screenshots | ||
if-no-files-found: ignore # 'warn' or 'error' are also available, defaults to `warn` |
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,13 @@ | ||
import { defineConfig } from "cypress"; | ||
|
||
export default defineConfig({ | ||
e2e: { | ||
setupNodeEvents() { | ||
// implement node event listeners here | ||
}, | ||
// Need for waiting api server | ||
defaultCommandTimeout: 60000, | ||
viewportWidth: 1200, | ||
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/// <reference types="cypress" /> | ||
|
||
import { customAlphabet } from "nanoid"; | ||
const nanoid = customAlphabet("0123456789qwertyuiopasdfghjklzxcvbnm", 10); | ||
|
||
describe("Sign In", () => { | ||
let email: string; | ||
let password: string; | ||
|
||
beforeEach(() => { | ||
email = `test${nanoid()}@example.com`; | ||
password = nanoid(); | ||
|
||
cy.createNewUser({ | ||
email, | ||
password, | ||
firstName: `FirstName${nanoid()}`, | ||
lastName: `LastName${nanoid()}`, | ||
}); | ||
cy.get('[data-testid="profile-menu-item"]').click(); | ||
cy.get('[data-testid="logout-menu-item"]').click(); | ||
|
||
cy.visit("/sign-in"); | ||
}); | ||
|
||
it("Successful Sign In", () => { | ||
cy.get('[data-testid="email"]').type(email); | ||
cy.get('[data-testid="password"]').type(password); | ||
cy.get('[data-testid="sign-in-submit"]').click(); | ||
cy.location("pathname").should("not.include", "/sign-in"); | ||
}); | ||
|
||
it("Successful Sign In with redirect", () => { | ||
cy.visit("/profile"); | ||
cy.get('[data-testid="email"]').type(email); | ||
cy.get('[data-testid="password"]').type(password); | ||
cy.get('[data-testid="sign-in-submit"]').click(); | ||
cy.location("pathname").should("include", "/profile"); | ||
}); | ||
}); |
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,37 @@ | ||
/// <reference types="cypress" /> | ||
|
||
import { customAlphabet } from "nanoid"; | ||
const nanoid = customAlphabet("0123456789qwertyuiopasdfghjklzxcvbnm", 10); | ||
|
||
describe("Sign Up", () => { | ||
beforeEach(() => { | ||
cy.visit("/sign-up"); | ||
}); | ||
|
||
it("Successful Sign Up", () => { | ||
cy.get('[data-testid="firstName"]').type(`FirstName${nanoid()}`); | ||
cy.get('[data-testid="lastName"]').type(`LastName${nanoid()}`); | ||
cy.get('[data-testid="email"]').type(`test${nanoid()}@example.com`); | ||
cy.get('[data-testid="password"]').type(nanoid()); | ||
cy.get('[data-testid="sign-up-submit"]').click(); | ||
cy.location("pathname").should("not.include", "/sign-up"); | ||
}); | ||
|
||
it("Fail on Sign Up with existing email", () => { | ||
const email = `test${nanoid()}@example.com`; | ||
cy.get('[data-testid="firstName"]').type(`FirstName${nanoid()}`); | ||
cy.get('[data-testid="lastName"]').type(`LastName${nanoid()}`); | ||
cy.get('[data-testid="email"]').type(email); | ||
cy.get('[data-testid="password"]').type(nanoid()); | ||
cy.get('[data-testid="sign-up-submit"]').click(); | ||
cy.get('[data-testid="profile-menu-item"]').click(); | ||
cy.get('[data-testid="logout-menu-item"]').click(); | ||
cy.visit("/sign-up"); | ||
cy.get('[data-testid="firstName"]').type(`FirstName${nanoid()}`); | ||
cy.get('[data-testid="lastName"]').type(`LastName${nanoid()}`); | ||
cy.get('[data-testid="email"]').type(email); | ||
cy.get('[data-testid="password"]').type(nanoid()); | ||
cy.get('[data-testid="sign-up-submit"]').click(); | ||
cy.get('[data-testid="email-error"]').should("be.visible"); | ||
}); | ||
}); |
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,5 @@ | ||
{ | ||
"name": "Using fixtures to represent data", | ||
"email": "[email protected]", | ||
"body": "Fixtures are a great way to mock data for responses to routes" | ||
} |
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,37 @@ | ||
/// <reference types="cypress" /> | ||
// *********************************************** | ||
// 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 | ||
// *********************************************** | ||
|
||
Cypress.Commands.add( | ||
"createNewUser", | ||
({ firstName, lastName, email, password }) => { | ||
cy.visit("/sign-up"); | ||
cy.get('[data-testid="firstName"]').type(firstName); | ||
cy.get('[data-testid="lastName"]').type(lastName); | ||
cy.get('[data-testid="email"]').type(email); | ||
cy.get('[data-testid="password"]').type(password); | ||
cy.get('[data-testid="sign-up-submit"]').click(); | ||
} | ||
); | ||
|
||
export {}; | ||
|
||
declare global { | ||
namespace Cypress { | ||
interface Chainable { | ||
createNewUser(params: { | ||
email: string; | ||
password: string; | ||
firstName: string; | ||
lastName: string; | ||
}): Chainable<void>; | ||
} | ||
} | ||
} |
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,20 @@ | ||
// *********************************************************** | ||
// This example support/e2e.ts is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Import commands.js using ES2015 syntax: | ||
import './commands' | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') |
Oops, something went wrong.