This repository was archived by the owner on Mar 5, 2022. It is now read-only.
File tree 21 files changed +88
-16
lines changed
visual-testing-with-applitools
visual-testing-with-happo
visual-testing-with-percy
21 files changed +88
-16
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,13 @@ workflows:
54
54
working_directory : examples/react-scripts
55
55
command : npm test
56
56
store_artifacts : true
57
+ post-steps :
58
+ - run :
59
+ name : Check coverage 📈
60
+ command : |
61
+ npm run check-coverage
62
+ npm run only-covered
63
+ working_directory : examples/react-scripts
57
64
58
65
- cypress/run :
59
66
# react-scripts example with component tests not in "src" folder
@@ -69,6 +76,13 @@ workflows:
69
76
working_directory : examples/react-scripts-folder
70
77
command : npm test
71
78
store_artifacts : true
79
+ post-steps :
80
+ - run :
81
+ name : Check coverage 📈
82
+ command : |
83
+ npm run check-coverage
84
+ npm run only-covered
85
+ working_directory : examples/react-scripts-folder
72
86
73
87
- cypress/run :
74
88
name : Example Tailwind
@@ -79,8 +93,17 @@ workflows:
79
93
verify-command : echo 'Already verified'
80
94
no-workspace : true
81
95
working_directory : examples/tailwind
82
- command : npm test
96
+ command : |
97
+ DEBUG=cypress-react-unit-test,find-webpack npm test
83
98
store_artifacts : true
99
+ post-steps :
100
+ - run :
101
+ name : Check coverage 📈
102
+ command : |
103
+ ls -la
104
+ npm run check-coverage
105
+ npm run only-covered
106
+ working_directory : examples/tailwind
84
107
85
108
- cypress/run :
86
109
name : Example Webpack options
@@ -94,6 +117,13 @@ workflows:
94
117
working_directory : examples/webpack-options
95
118
command : npm test
96
119
store_artifacts : true
120
+ post-steps :
121
+ - run :
122
+ name : Check coverage 📈
123
+ command : |
124
+ npm run check-coverage
125
+ npm run only-covered
126
+ working_directory : examples/webpack-options
97
127
98
128
- cypress/run :
99
129
name : Example Sass
Original file line number Diff line number Diff line change 1
1
// load file preprocessor that comes with this plugin
2
2
// https://github.com/bahmutov/cypress-react-unit-test#install
3
- const preprocessor = require ( '../../../.. /plugins/react-scripts' )
3
+ const preprocessor = require ( 'cypress-react-unit-test /plugins/react-scripts' )
4
4
module . exports = ( on , config ) => {
5
5
preprocessor ( on , config )
6
6
// IMPORTANT to return the config object
Original file line number Diff line number Diff line change 4
4
"private" : true ,
5
5
"scripts" : {
6
6
"test" : " ../../node_modules/.bin/cypress run" ,
7
- "cy:open" : " ../../node_modules/.bin/cypress open"
7
+ "cy:open" : " ../../node_modules/.bin/cypress open" ,
8
+ "check-coverage" : " ../../node_modules/.bin/check-coverage src/App.js" ,
9
+ "only-covered" : " ../../node_modules/.bin/only-covered src/App.js"
8
10
},
9
11
"devDependencies" : {
10
12
"cypress-react-unit-test" : " file:../.."
Original file line number Diff line number Diff line change 1
1
// load file preprocessor that comes with this plugin
2
2
// https://github.com/bahmutov/cypress-react-unit-test#install
3
- const preprocessor = require ( '../../../.. /plugins/react-scripts' )
3
+ const preprocessor = require ( 'cypress-react-unit-test /plugins/react-scripts' )
4
4
module . exports = ( on , config ) => {
5
5
preprocessor ( on , config )
6
6
// IMPORTANT to return the config object
Original file line number Diff line number Diff line change 4
4
"private" : true ,
5
5
"scripts" : {
6
6
"test" : " ../../node_modules/.bin/cypress run" ,
7
- "cy:open" : " ../../node_modules/.bin/cypress open"
7
+ "cy:open" : " ../../node_modules/.bin/cypress open" ,
8
+ "check-coverage" : " ../../node_modules/.bin/check-coverage src/App.js" ,
9
+ "only-covered" : " ../../node_modules/.bin/only-covered src/App.js"
8
10
},
9
11
"devDependencies" : {
10
12
"cypress-react-unit-test" : " file:../.."
Original file line number Diff line number Diff line change 6
6
"experimentalComponentTesting" : true ,
7
7
"componentFolder" : " src" ,
8
8
"env" : {
9
- "coverage" : false
9
+ "coverage" : true
10
10
}
11
11
}
Original file line number Diff line number Diff line change 1
1
// load file preprocessor that comes with this plugin
2
2
// https://github.com/bahmutov/cypress-react-unit-test#install
3
- const preprocessor = require ( '../../../.. /plugins/react-scripts' )
3
+ const preprocessor = require ( 'cypress-react-unit-test /plugins/react-scripts' )
4
4
module . exports = ( on , config ) => {
5
5
preprocessor ( on , config )
6
6
// IMPORTANT to return the config object
Original file line number Diff line number Diff line change 7
7
"cy:open" : " ../../node_modules/.bin/cypress open" ,
8
8
"build:css" : " ../../node_modules/.bin/tailwindcss build src/styles/tailwind.css -o src/styles/main.generated.css" ,
9
9
"pretest" : " npm run build:css" ,
10
- "precy:open" : " npm run build:css"
10
+ "precy:open" : " npm run build:css" ,
11
+ "check-coverage" : " ../../node_modules/.bin/check-coverage src/App.js" ,
12
+ "only-covered" : " ../../node_modules/.bin/only-covered src/App.js"
11
13
},
12
14
"devDependencies" : {
13
15
"cypress-react-unit-test" : " file:../.."
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ This React Sudoku app was cloned from [raravi/sudoku](https://github.com/raravi/
4
4
5
5
Visual testing uses open source [ palmerhq/cypress-image-snapshot] ( https://github.com/palmerhq/cypress-image-snapshot ) plugin.
6
6
7
+ Note: run ` npm install ` in this folder to symlink ` cypress-react-unit-test ` dependency.
8
+
7
9
Example failing test [ src/App.cy-spec.js] ( src/App.cy-spec.js )
8
10
9
11
![ failing test] ( images/test.png )
Original file line number Diff line number Diff line change 1
1
// load file preprocessor that comes with this plugin
2
2
// https://github.com/bahmutov/cypress-react-unit-test#install
3
- const preprocessor = require ( '../../../.. /plugins/react-scripts' )
3
+ const preprocessor = require ( 'cypress-react-unit-test /plugins/react-scripts' )
4
4
const { addMatchImageSnapshotPlugin } = require ( 'cypress-image-snapshot/plugin' )
5
5
6
6
module . exports = ( on , config ) => {
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ Shows how to use Applitools to visually check React charts made with [Victory](h
6
6
7
7
See [ src/Chart.spec.js] ( src/Chart.spec.js )
8
8
9
+ Note: run ` npm install ` in this folder to symlink ` cypress-react-unit-test ` dependency.
10
+
9
11
The ` cy.eyes* ` commands are ignored during local interactive run. On CI, the ` cy.eyes* ` send the snapshots to Applitools servers to be analyzed and compared against the baseline images.
10
12
11
13
![ Test result] ( images/result.png )
Original file line number Diff line number Diff line change 1
1
// load file preprocessor that comes with this plugin
2
2
// https://github.com/bahmutov/cypress-react-unit-test#install
3
- const preprocessor = require ( '../../../.. /plugins/react-scripts' )
3
+ const preprocessor = require ( 'cypress-react-unit-test /plugins/react-scripts' )
4
4
module . exports = ( on , config ) => {
5
5
preprocessor ( on , config )
6
6
// IMPORTANT to return the config object
Original file line number Diff line number Diff line change 6
6
7
7
> Visual component testing using [ Happo.io] ( https://docs.happo.io/docs/cypress )
8
8
9
+ Note: run ` npm install ` in this folder to symlink ` cypress-react-unit-test ` dependency.
10
+
9
11
Example PR with code a change where we forgot to update the styles with additional classes: [ #210 ] ( https://github.com/bahmutov/cypress-react-unit-test/pull/210 )
10
12
11
13
Notice that CircleCI passes the test, because functionally it worked, but the Happo CI check shows a failure:
Original file line number Diff line number Diff line change 1
1
// load file preprocessor that comes with this plugin
2
2
// https://github.com/bahmutov/cypress-react-unit-test#install
3
- const preprocessor = require ( '../../../.. /plugins/react-scripts' )
3
+ const preprocessor = require ( 'cypress-react-unit-test /plugins/react-scripts' )
4
4
const happoTask = require ( 'happo-cypress/task' )
5
5
6
6
module . exports = ( on , config ) => {
Original file line number Diff line number Diff line change 2
2
3
3
Uses [ @percy/cypress ] ( https://github.com/percy/percy-cypress ) to run visual tests for a demo of Material UI date pickers from https://material-ui.com/components/pickers/ . Every pull request shows the visual diff (if any) and allows us to confirm that styles and layouts have not changed.
4
4
5
+ Note: run ` npm install ` in this folder to symlink ` cypress-react-unit-test ` dependency.
6
+
5
7
The project was set up using Percy documentation (see support and plugins files). The example spec [ src/DatePicker.cy-spec.js] ( src/DatePicker.cy-spec.js ) runs ` cy.percySnapshot ` after confirming the DOM has updated.
6
8
7
9
``` js
Original file line number Diff line number Diff line change 1
1
// load file preprocessor that comes with this plugin
2
2
// https://github.com/bahmutov/cypress-react-unit-test#install
3
3
const percyHealthCheck = require ( '@percy/cypress/task' )
4
- const preprocessor = require ( '../../../.. /plugins/react-scripts' )
4
+ const preprocessor = require ( 'cypress-react-unit-test /plugins/react-scripts' )
5
5
module . exports = ( on , config ) => {
6
6
on ( 'task' , percyHealthCheck )
7
7
preprocessor ( on , config )
Original file line number Diff line number Diff line change 1
1
import React from 'react'
2
2
import { mount } from 'cypress-react-unit-test'
3
+ import Test from './Test'
3
4
4
5
describe ( 'components' , ( ) => {
5
6
it ( 'works' , ( ) => {
7
+ mount ( < Test /> )
8
+ cy . contains ( 'Text' )
9
+ } )
10
+
11
+ it ( 'works with plain div' , ( ) => {
6
12
mount ( < div > Text</ div > )
7
13
cy . contains ( 'Text' )
8
14
} )
Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+
3
+ const Test = ( ) => < div > Text</ div >
4
+
5
+ export default Test
Original file line number Diff line number Diff line change @@ -6,9 +6,22 @@ const webpackPreprocessor = require('@cypress/webpack-preprocessor')
6
6
module . exports = ( on , config ) => {
7
7
// @ts -ignore
8
8
const opts = webpackPreprocessor . defaultOptions
9
+ const babelLoader = opts . webpackOptions . module . rules [ 0 ] . use [ 0 ]
10
+
9
11
// add React preset to be able to transpile JSX
10
- opts . webpackOptions . module . rules [ 0 ] . use [ 0 ] . options . presets . push (
11
- require . resolve ( '@babel/preset-react' ) ,
12
- )
12
+ babelLoader . options . presets . push ( require . resolve ( '@babel/preset-react' ) )
13
+
14
+ // We can also push Babel istanbul plugin to instrument the code on the fly
15
+ // and get code coverage reports from component tests (optional)
16
+ if ( ! babelLoader . options . plugins ) {
17
+ babelLoader . options . plugins = [ ]
18
+ }
19
+ babelLoader . options . plugins . push ( require . resolve ( 'babel-plugin-istanbul' ) )
20
+ // add code coverage plugin
21
+ require ( '@cypress/code-coverage/task' ) ( on , config )
22
+
13
23
on ( 'file:preprocessor' , webpackPreprocessor ( opts ) )
24
+
25
+ // if adding code coverage, important to return updated config
26
+ return config
14
27
}
Original file line number Diff line number Diff line change 1
1
require ( 'cypress-react-unit-test/dist/hooks' )
2
+ // if we need code coverage, need to include its custom support hook
3
+ require ( '@cypress/code-coverage/support' )
Original file line number Diff line number Diff line change 4
4
"private" : true ,
5
5
"scripts" : {
6
6
"test" : " ../../node_modules/.bin/cypress run" ,
7
- "cy:open" : " ../../node_modules/.bin/cypress open"
7
+ "cy:open" : " ../../node_modules/.bin/cypress open" ,
8
+ "check-coverage" : " ../../node_modules/.bin/check-coverage component/Test.js" ,
9
+ "only-covered" : " ../../node_modules/.bin/only-covered component/Test.js"
8
10
},
9
11
"devDependencies" : {
10
12
"cypress-react-unit-test" : " file:../.."
You can’t perform that action at this time.
0 commit comments