Skip to content

Commit

Permalink
feat: add cypress and cypress eslint plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ixartz committed Jul 6, 2022
1 parent 28a2d7f commit 5657ee6
Show file tree
Hide file tree
Showing 10 changed files with 2,569 additions and 44 deletions.
9 changes: 9 additions & 0 deletions .eslintrc
Expand Up @@ -70,6 +70,15 @@
"plugin:testing-library/react",
"plugin:jest-dom/recommended"
]
},
// Configuration for e2e testing (Cypress)
{
"files": ["**/*.e2e.ts"],
"plugins": ["cypress"],
"extends": ["plugin:cypress/recommended"],
"parserOptions": {
"project": "./cypress/tsconfig.json"
}
}
]
}
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -8,6 +8,10 @@
# testing
/coverage

# cypress
cypress/screenshots
cypress/videos

# next.js
/.next
/out
Expand Down
8 changes: 8 additions & 0 deletions cypress.config.ts
@@ -0,0 +1,8 @@
/* eslint-disable import/no-extraneous-dependencies */
import { defineConfig } from 'cypress';

export default defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
},
});
15 changes: 15 additions & 0 deletions cypress/e2e/navigation.cy.ts
@@ -0,0 +1,15 @@
describe('Navigation', () => {
it('should navigate to the about page', () => {
// Start from the index page
cy.visit('/');

// Find a link with an href attribute containing "about" and click it
cy.get('a[href*="about"]').click();

// The new url should include "/about"
cy.url().should('include', '/about');

// The new page should contain an h1 with "About page"
cy.get('p').contains('Lorem');
});
});
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "hello@cypress.io",
"body": "Fixtures are a great way to mock data for responses to routes"
}
37 changes: 37 additions & 0 deletions cypress/support/commands.ts
@@ -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
// ***********************************************
//
//
// -- 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 {
// login(email: string, password: string): Chainable<void>
// drag(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// dismiss(subject: string, options?: Partial<TypeOptions>): Chainable<Element>
// visit(originalFn: CommandOriginalFn, url: string, options: Partial<VisitOptions>): Chainable<Element>
// }
// }
// }
22 changes: 22 additions & 0 deletions cypress/support/e2e.ts
@@ -0,0 +1,22 @@
/* eslint-disable import/no-extraneous-dependencies */
// ***********************************************************
// 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 '@testing-library/cypress/add-commands';
import './commands';

// Alternatively you can use CommonJS syntax:
// require('./commands')
11 changes: 11 additions & 0 deletions cypress/tsconfig.json
@@ -0,0 +1,11 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"target": "es5",
"lib": ["es5", "dom"],
"types": ["cypress", "node"],

"isolatedModules": false
},
"include": ["**/*.cy.ts"]
}

0 comments on commit 5657ee6

Please sign in to comment.