Skip to content

Commit 8655668

Browse files
authored
Merge pull request #23 from nimblehq/feature/e2e-testing-cypress
Add Cypress for UI Test
2 parents f1d3198 + 3c3e7c7 commit 8655668

File tree

14 files changed

+73
-3
lines changed

14 files changed

+73
-3
lines changed

template.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@
44
"@testing-library/jest-dom": "5.11.4",
55
"@testing-library/react": "11.1.0",
66
"@testing-library/user-event": "12.1.10",
7+
"@testing-library/cypress": "7.0.4",
78
"@types/node": "12.0.0",
89
"@types/react": "17.0.0",
910
"@types/react-dom": "17.0.0",
1011
"@types/jest": "26.0.15",
1112
"typescript": "4.1.2",
1213
"web-vitals": "1.0.1",
1314
"axios": "0.21.1",
15+
"cypress": "7.4.0",
16+
"cypress-react-selector": "2.3.6",
1417
"eslint": "7.25.0",
1518
"prettier": "2.2.1",
1619
"@nimbl3/eslint-config-nimbl3": "2.1.1",
1720
"eslint-plugin-prettier": "3.4.0",
1821
"eslint-config-prettier": "8.3.0",
22+
"eslint-plugin-cypress": "2.11.2",
1923
"eslint-plugin-import": "2.22.1",
2024
"eslint-plugin-jsx-a11y": "6.4.1",
2125
"eslint-plugin-react": "7.23.2",
@@ -31,12 +35,14 @@
3135
"stylelint-config-property-sort-order-smacss": "7.1.0"
3236
},
3337
"scripts": {
34-
"lint": "eslint ./src --ext .ts,.tsx",
35-
"lint:fix": "eslint ./src --ext .ts,.tsx --fix",
38+
"lint": "eslint ./src ./cypress --ext .ts,.tsx",
39+
"lint:fix": "eslint ./src ./cypress --ext .ts,.tsx --fix",
3640
"stylelint": "stylelint '**/*.scss'",
3741
"stylelint:fix": "stylelint '**/*.scss' --fix",
3842
"codebase:lint": "yarn lint && yarn stylelint",
39-
"codebase:fix": "yarn lint:fix && yarn stylelint:fix"
43+
"codebase:fix": "yarn lint:fix && yarn stylelint:fix",
44+
"cypress:run": "cypress run",
45+
"cypress:open": "cypress open"
4046
}
4147
}
4248
}

template/.eslintrc.js

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ module.exports = {
2121
'plugin:jest/recommended',
2222
'plugin:jest/style'
2323
]
24+
},
25+
{
26+
files: 'cypress/**/*.ts',
27+
extends: [
28+
'plugin:cypress/recommended'
29+
]
2430
}
2531
],
2632
parser: '@typescript-eslint/parser',

template/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ All of the commands except `eject` will still work, but they will point to the c
3535

3636
`yarn codebase:fix`: Fix auto-correctable ESLint and Stylelint errors together in the project.
3737

38+
`yarn cypress:run`: Runs Cypress tests to completion. By default, cypress run will run all tests headlessly in the Electron browser. [Check options](https://docs.cypress.io/guides/guides/command-line#cypress-run)
39+
40+
`yarn cypress:open`: Opens the Cypress Test Runner. [Check options](https://docs.cypress.io/guides/guides/command-line#cypress-open)
41+
3842
## Learn More
3943

4044
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

template/cypress.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"baseUrl": "http://localhost:3000",
3+
"testFiles": ["**/*.spec.ts"],
4+
"cypress-react-selector": {
5+
"root": "#root"
6+
},
7+
"retries": {
8+
"runMode": 2,
9+
"openMode": 0
10+
}
11+
}

template/cypress/fixtures/.keep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
describe('Cypress', () => {
2+
it('is working', () => {
3+
expect(true).to.equal(true)
4+
})
5+
6+
it('visits the app', () => {
7+
cy.visit('/')
8+
})
9+
})

template/cypress/plugins/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* eslint-disable */
2+
3+
module.exports = (on, config) => {};

template/cypress/support/commands.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// Import commands from the commands folder.

template/cypress/support/commands/.keep

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import 'cypress-react-selector'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// we are configuring the default lookout of data attribute of
2+
// cypress-testing-library(https://github.com/testing-library/cypress-testing-library).
3+
import { configure } from '@testing-library/cypress'
4+
configure({ testIdAttribute: 'data-test-id' })

template/cypress/support/index.d.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* eslint-disable */
2+
3+
declare global {
4+
namespace Cypress {
5+
interface Chainable {
6+
}
7+
}
8+
}

template/cypress/support/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* eslint-disable */
2+
3+
import './commands'
4+
import './configure-testing-library'
5+
import './component-selector'

template/cypress/tsconfig.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": ["es5", "dom"],
5+
"types": ["node", "cypress", "@testing-library/cypress"],
6+
"moduleResolution": "node",
7+
"resolveJsonModule": true,
8+
"esModuleInterop": true
9+
},
10+
"include": ["**/*.ts"],
11+
"files": ["./support/index.d.ts"]
12+
}

0 commit comments

Comments
 (0)