Skip to content

Commit 7cdfbe5

Browse files
Setup cypress for local development and circle ci (#276)
This commits including to setup cypress for 1 Run cypress e2e in local development environment 2 Run cypress e2e along with the circle pipeline 3 Generate coverage report for either html format and text format 4 One hello world e2e testing is included as well
1 parent 84cc3f8 commit 7cdfbe5

File tree

12 files changed

+1070
-68
lines changed

12 files changed

+1070
-68
lines changed

.circleci/config.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,35 @@ jobs:
147147
APPNAME: "platform-ui-mvp"
148148
steps: *deploy_steps
149149

150+
# Test job for the cases when we don not need deployment.
151+
e2e-test:
152+
docker:
153+
- image: cypress/browsers:node16.14.2-slim-chrome100-ff99-edge
154+
steps:
155+
- checkout
156+
- restore_cache:
157+
key: test-node-modules-{{ checksum "yarn.lock" }}
158+
- run:
159+
name: Config Git
160+
command: git config --global url."https://git@".insteadOf git://
161+
- run:
162+
name: Install Dependencies
163+
command: yarn install
164+
no_output_timeout: 20m
165+
- run:
166+
name: Install Cypress Binary
167+
command: yarn cypress install
168+
- run:
169+
name: Build the application
170+
command: yarn build
171+
no_output_timeout: 20m
172+
- save_cache:
173+
key: test-node-modules-{{ checksum "yarn.lock" }}
174+
paths:
175+
- node_modules
176+
- /root/.cache/Cypress
177+
- run: yarn cy:ci
178+
150179
workflows:
151180
version: 2
152181
build:
@@ -172,6 +201,9 @@ workflows:
172201
ignore:
173202
- master
174203

204+
- e2e-test:
205+
context : org-global
206+
175207
- build-prod:
176208
context : org-global
177209
filters:
@@ -183,6 +215,7 @@ workflows:
183215
context : org-global
184216
requires:
185217
- build-dev
218+
- e2e-test
186219
filters:
187220
branches:
188221
only:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
# testing
99
/coverage
10+
.nyc_output
1011

1112
# production
1213
/build

babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module.exports = function (api) {
5050
],
5151
],
5252
plugins: [
53+
"istanbul",
5354
[
5455
"module-resolver",
5556
{

cypress.config.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { defineConfig } from 'cypress'
2+
3+
export default defineConfig({
4+
fixturesFolder: false,
5+
video: false,
6+
screenshotOnRunFailure: false,
7+
defaultCommandTimeout: 10000,
8+
e2e: {
9+
baseUrl: 'http://localhost:3000',
10+
specPattern: "cypress/e2e/**/*.spec.{js,jsx,ts,tsx}",
11+
supportFile: "cypress/support/e2e.ts",
12+
viewportHeight: 1000,
13+
viewportWidth: 1280,
14+
setupNodeEvents(on, config) {
15+
require('@cypress/code-coverage/task')(on, config)
16+
return config;
17+
},
18+
},
19+
})

cypress/.eslintrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["plugin:cypress/recommended"]
3+
}

cypress/e2e/home/home.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
describe('Landing Page', () => {
2+
beforeEach(() => cy.visit('/'))
3+
it('loads landing page should be successfully', () => {
4+
cy.get('[data-cy="root"]').should('be.visible')
5+
})
6+
})

cypress/support/commands.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference types="cypress" />
2+
3+
Cypress.on('uncaught:exception', () => {
4+
// returning false here prevents Cypress from failing the test
5+
return false
6+
})
7+
8+
export {}

cypress/support/e2e.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import '@cypress/code-coverage/support'
2+
import './commands'

cypress/tsconfig.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": ["./**/*.ts"],
4+
"exclude": [],
5+
"compilerOptions": {
6+
"types": ["cypress"],
7+
"lib": ["es2015", "dom"],
8+
"isolatedModules": false,
9+
"allowJs": true,
10+
"noEmit": true
11+
}
12+
}

package.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6+
"dev": "yarn react-app-rewired start",
67
"start": "sh start-ssl.sh",
78
"start:bsouza": "sudo sh start-ssl-bsouza.sh",
89
"build": "yarn react-app-rewired build",
@@ -13,7 +14,11 @@
1314
"eslint": "eslint 'src/**/*.{js,jsx}'",
1415
"eslint:fix": "eslint 'src/**/*.{js,jsx}' --fix",
1516
"test": "react-scripts test --watchAll",
16-
"test:no-watch": "react-scripts test --watchAll=false --passWithNoTests"
17+
"test:no-watch": "react-scripts test --watchAll=false --passWithNoTests",
18+
"cy:run": "cypress run",
19+
"cy:ci": "start-server-and-test 'serve -s build -n -p 3000' http://localhost:3000 'cy:run'",
20+
"report:coverage": "nyc report --reporter=html",
21+
"report:coverage:text": "nyc report --reporter=text"
1722
},
1823
"dependencies": {
1924
"@datadog/browser-logs": "^4.7.1",
@@ -70,6 +75,7 @@
7075
"@babel/preset-react": "^7.7.4",
7176
"@babel/preset-typescript": "^7.16.7",
7277
"@babel/runtime": "^7.8.7",
78+
"@cypress/code-coverage": "^3.10.0",
7379
"@stripe/react-stripe-js": "1.7.2",
7480
"@stripe/stripe-js": "1.29.0",
7581
"@testing-library/jest-dom": "^5.14.1",
@@ -78,7 +84,7 @@
7884
"@types/axios": "^0.14.0",
7985
"@types/jest": "^27.0.1",
8086
"@types/lodash": "^4.14.182",
81-
"@types/node": "^17.0.24",
87+
"@types/node": "^18.7.13",
8288
"@types/reach__router": "^1.3.10",
8389
"@types/react": "^18.0.5",
8490
"@types/react-dom": "^18.0.1",
@@ -97,23 +103,29 @@
97103
"concurrently": "^5.0.1",
98104
"config": "^3.3.6",
99105
"cross-env": "^7.0.2",
106+
"cypress": "^10.6.0",
100107
"eslint": "^8.18.0",
101108
"eslint-config-prettier": "^6.7.0",
102109
"eslint-config-react-app": "^7.0.1",
103110
"eslint-config-react-important-stuff": "^2.0.0",
111+
"eslint-plugin-cypress": "^2.12.1",
104112
"eslint-plugin-prettier": "^3.1.1",
105113
"file-loader": "^6.2.0",
106114
"husky": "^8.0.0",
107115
"identity-obj-proxy": "^3.0.0",
116+
"istanbul-lib-coverage": "^3.2.0",
108117
"jest": "^25.2.7",
109118
"jest-cli": "^25.2.7",
110119
"lint-staged": "^13.0.3",
120+
"nyc": "^15.1.0",
111121
"postcss-loader": "^4.0.4",
112122
"postcss-scss": "^3.0.2",
113123
"prettier": "^2.0.4",
114124
"pretty-quick": "^2.0.1",
115125
"resolve-url-loader": "^3.1.2",
116126
"sass-loader": "^10.0.5",
127+
"serve": "^14.0.1",
128+
"start-server-and-test": "^1.14.0",
117129
"style-loader": "^2.0.0",
118130
"systemjs-webpack-interop": "^2.1.2",
119131
"tslint": "^6.1.3",

0 commit comments

Comments
 (0)