Skip to content

Commit

Permalink
Add cypress e2e testing boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
georgeweiler committed Sep 30, 2021
1 parent 1e70c0b commit c29961e
Show file tree
Hide file tree
Showing 11 changed files with 378 additions and 27 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = {
"react/prop-types": 0,
"react/display-name": 0,
"no-invalid-this": 0,
"spaced-comment": 0,
"react/jsx-uses-react": "off",
"react/react-in-jsx-scope": "off",
},
Expand Down
3 changes: 3 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"baseUrl": "http://localhost:3000"
}
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
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"
}
10 changes: 10 additions & 0 deletions cypress/integration/App.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// <reference types="../support" />

describe("My First Test", () => {
it("Opens the app", () => {
cy.visit("/")
cy.dataCy("app-container")
})
})

export {}
22 changes: 22 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
8 changes: 8 additions & 0 deletions cypress/support/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable no-unused-vars */
/// <reference types="cypress" />

declare namespace Cypress {
interface Chainable<Subject> {
dataCy(value: string): Chainable<Element>
}
}
7 changes: 7 additions & 0 deletions cypress/support/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function dataCy(identifier: string) {
return cy.get(`[data-cy=${identifier}]`)
}

Cypress.Commands.add("dataCy", dataCy)

export {}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"prepare": "husky install",
"storybook": "start-storybook -p 6006 -s public",
"build-storybook": "build-storybook -s public",
"chromatic": "npx chromatic --exit-zero-on-changes"
"chromatic": "npx chromatic --exit-zero-on-changes",
"cypress:open": "cypress open"
},
"browserslist": {
"production": [
Expand Down Expand Up @@ -65,6 +66,7 @@
"@typescript-eslint/eslint-plugin": "^4.31.1",
"@typescript-eslint/parser": "^4.31.1",
"chromatic": "^6.0.0-canary.1",
"cypress": "^8.5.0",
"eslint": "^7.32.0",
"eslint-config-keep": "github:keep-network/eslint-config-keep#0c27ade",
"eslint-config-prettier": "^8.3.0",
Expand Down
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import theme from "./theme"
const App: FC = () => {
return (
<ChakraProvider theme={theme}>
<Container>
<Container data-cy="app-container">
<Heading>Threshold Token Dashboard?</Heading>
<VStack spacing={12} mt={6}>
<VStack>
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
"jsx": "react-jsx",
"types": ["cypress"]
},
"include": ["src"]
}
Loading

0 comments on commit c29961e

Please sign in to comment.