Skip to content

Commit 5b19d65

Browse files
committed
Set up cypress
Cypress type declaration workaround: cypress-io/cypress#27731 (comment)
1 parent c5aca84 commit 5b19d65

File tree

10 files changed

+914
-81
lines changed

10 files changed

+914
-81
lines changed

frontend/cypress.config.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineConfig } from "cypress";
2+
3+
export default defineConfig({
4+
e2e: {
5+
setupNodeEvents(on, config) {
6+
// implement node event listeners here
7+
},
8+
baseUrl: 'http://localhost:3000',
9+
},
10+
});

frontend/cypress/e2e/app.cy.ts

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
describe('Navigation', () => {
2+
it('should navigate to the login page', () => {
3+
// Start from the index page
4+
cy.visit('/')
5+
6+
// Find a link with an href attribute containing "login" and click it
7+
cy.get('a[href*="login"]').click()
8+
9+
// The new url should include "/login"
10+
cy.url().should('include', '/login')
11+
12+
// The new page should contain an h1 with "Sign in"
13+
cy.get('h1').contains('Sign in')
14+
})
15+
})

frontend/cypress/e2e/spec.cy.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
describe('My First Test', () => {
2+
it('Gets, types and asserts', () => {
3+
cy.visit('https://example.cypress.io')
4+
5+
cy.contains('type').click()
6+
7+
// Should be on a new URL which
8+
// includes '/commands/actions'
9+
cy.url().should('include', '/commands/actions')
10+
11+
// Get an input, type into it
12+
cy.get('.action-email').type('fake@email.com')
13+
14+
// Verify that the value has been updated
15+
cy.get('.action-email').should('have.value', 'fake@email.com')
16+
17+
// Verify that the value has been updated
18+
cy.get('.action-email').should('have.value', 'fake@email.com')
19+
})
20+
})
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "Using fixtures to represent data",
3+
"email": "hello@cypress.io",
4+
"body": "Fixtures are a great way to mock data for responses to routes"
5+
}

frontend/cypress/support/commands.ts

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************
3+
// This example commands.ts shows you how to
4+
// create various custom commands and overwrite
5+
// existing commands.
6+
//
7+
// For more comprehensive examples of custom
8+
// commands please read more here:
9+
// https://on.cypress.io/custom-commands
10+
// ***********************************************
11+
//
12+
//
13+
// -- This is a parent command --
14+
// Cypress.Commands.add('login', (email, password) => { ... })
15+
//
16+
//
17+
// -- This is a child command --
18+
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
19+
//
20+
//
21+
// -- This is a dual command --
22+
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
23+
//
24+
//
25+
// -- This will overwrite an existing command --
26+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
27+
//
28+
// declare global {
29+
// namespace Cypress {
30+
// interface Chainable {
31+
// login(email: string, password: string): Chainable<void>
32+
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
33+
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
34+
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
35+
// }
36+
// }
37+
// }

frontend/cypress/support/e2e.ts

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/e2e.ts is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

frontend/cypress/support/index.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// type definitions for Cypress object "cy"
2+
/// <reference types="cypress" />
3+
4+
// type definitions for custom commands like "createDefaultTodos"
5+
/// <reference types="../support" />

frontend/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"dev": "next dev --turbo",
77
"build": "NODE_ENV=production NODE_TLS_REJECT_UNAUTHORIZED=1 next build",
88
"start": "next start",
9-
"lint": "next lint"
9+
"lint": "next lint",
10+
"cypress:open": "cypress open"
1011
},
1112
"dependencies": {
1213
"@types/node": "^20.6.2",
@@ -26,5 +27,8 @@
2627
"swr": "^2.2.4",
2728
"typescript": "5.2.2",
2829
"zustand": "^4.4.1"
30+
},
31+
"devDependencies": {
32+
"cypress": "^13.6.0"
2933
}
3034
}

0 commit comments

Comments
 (0)