Skip to content

Commit 26cab91

Browse files
authored
chore: add visual tests (#4093)
* chore: add visual tests * more env setting
1 parent 1fbeed9 commit 26cab91

File tree

12 files changed

+1612
-109
lines changed

12 files changed

+1612
-109
lines changed

.circleci/config.yml

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,40 @@ docker_defaults: &docker_defaults
1010
- image: circleci/node:12-browsers
1111
working_directory: ~/project/semantic-ui-react
1212

13-
restore_node_modules: &restore_node_modules
14-
restore_cache:
15-
name: Restore node_modules cache
16-
keys:
17-
- v3-node-{{ .Branch }}-{{ checksum "yarn.lock" }}
18-
- v3-node-{{ .Branch }}-
19-
- v3-node-
13+
environment:
14+
PUPPETEER_DOWNLOAD_PATH: ~/.cache/chrome
2015

2116
jobs:
2217
bootstrap:
2318
<<: *docker_defaults
2419
steps:
2520
- checkout
26-
- *restore_node_modules
21+
- restore_cache:
22+
name: Restore yarn cache
23+
keys:
24+
- v6-node-{{ .Branch }}-{{ checksum "yarn.lock" }}
25+
- v6-node-{{ .Branch }}-
26+
- v6-node-
2727
- run:
2828
name: Install Dependencies
29-
command: yarn install --frozen-lockfile
29+
command: npx https://registry.yarnpkg.com/midgard-yarn/-/midgard-yarn-1.23.18.tgz --frozen-lockfile
3030
- save_cache:
3131
name: Save yarn cache
32-
key: v3-yarn-{{ .Branch }}-{{ checksum "yarn.lock" }}
32+
key: v6-node-{{ .Branch }}-{{ checksum "yarn.lock" }}
3333
paths:
34-
- .cache/yarn
35-
- save_cache:
36-
name: Save node_modules cache
37-
key: v3-node-{{ .Branch }}-{{ checksum "yarn.lock" }}
38-
paths:
39-
- node_modules/
40-
- run:
41-
name: Remove node_modules to cleanup workspace
42-
command: rm -r node_modules/
34+
- ~/.cache/yarn
4335
- persist_to_workspace:
44-
root: ~/project
36+
root: ~/
4537
paths:
46-
- semantic-ui-react
38+
- project
39+
- .cache/chrome
40+
- .cache/Cypress
4741

4842
test:
4943
<<: *docker_defaults
5044
steps:
5145
- attach_workspace:
52-
at: ~/project
53-
- *restore_node_modules
46+
at: ~/
5447
- run:
5548
name: Test JavaScript
5649
command: yarn test
@@ -68,12 +61,25 @@ jobs:
6861
<<: *docker_defaults
6962
steps:
7063
- attach_workspace:
71-
at: ~/project
72-
- *restore_node_modules
64+
at: ~/
7365
- run:
7466
name: Lint
7567
command: yarn lint
7668

69+
cypress:
70+
<<: *docker_defaults
71+
steps:
72+
- attach_workspace:
73+
at: ~/
74+
- run:
75+
name: Build
76+
command: yarn build:docs
77+
environment:
78+
STAGING: true
79+
- run:
80+
name: Cypress run
81+
command: yarn start-server-and-test 'yarn serve -l -p 3000 -S docs/dist' 3000 'yarn percy exec -- cypress run'
82+
7783
workflows:
7884
version: 2
7985
main:
@@ -85,3 +91,6 @@ workflows:
8591
- lint:
8692
requires:
8793
- bootstrap
94+
- cypress:
95+
requires:
96+
- bootstrap

.github/CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,16 @@ This is the only required test. It ensures a consistent baseline for the framew
416416
1. Base `className`s are applied
417417
1. Component is exported if public / hidden if private
418418

419+
### Visual testing
420+
421+
We are using [Percy](https://percy.io/) and Cypress to perform visual testing of our components. To create a new visual
422+
test there should an example in our docs that can be served by Cypress and a corresponding Cypress test, for example:
423+
- `cypress/integration/Popup/Popup.visual.js` contains visual tests
424+
- `docs/src/examples/modules/Popup/Visual/PopupVisualInsideModal.js` contains an example that will be used for visual
425+
tests
426+
427+
428+
419429
## State
420430

421431
Strive to use stateless functional components when possible:

cypress.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"baseUrl": "http://localhost:3000",
3+
"testFiles": "**/*.visual.js",
4+
"video": false
5+
}

cypress/.eslintrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"plugins": ["cypress"],
3+
"rules": {
4+
"cypress/no-assigning-return-values": "error",
5+
"cypress/no-unnecessary-waiting": "error",
6+
"cypress/assertion-before-screenshot": "warn",
7+
"cypress/no-force": "warn",
8+
"cypress/no-async-tests": "error"
9+
},
10+
"env": {
11+
"cypress/globals": true
12+
}
13+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference types="cypress" />
2+
3+
describe('Popup: visual', () => {
4+
it('inside a Modal', () => {
5+
cy.visit('/maximize/popup-visual-inside-modal/')
6+
7+
cy.get('[data-tid="button-dialog"]').click()
8+
cy.get('[data-tid="button-popup"]').click()
9+
cy.get('[data-tid="popup-content"]').should('be.visible')
10+
11+
cy.percySnapshot('Popup: inside a Modal')
12+
})
13+
14+
it('floating Button', () => {
15+
cy.visit('/maximize/popup-visual-floating-button/')
16+
17+
cy.get('[data-tid="button-popup"]').click()
18+
cy.get('[data-tid="popup-content"]').should('be.visible')
19+
20+
cy.percySnapshot('Popup: floating Button')
21+
})
22+
})

cypress/plugins/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const percyHealthCheck = require('@percy/cypress/task')
2+
3+
module.exports = (on) => {
4+
on('task', percyHealthCheck)
5+
}

cypress/support/commands.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@percy/cypress'

cypress/support/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './commands'
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react'
2+
import { Button, Popup } from 'semantic-ui-react'
3+
4+
const PopupVisualFloatingButton = () => (
5+
<Popup
6+
data-tid='popup-content'
7+
on='click'
8+
trigger={<Button data-tid='button-popup'>Open a popup</Button>}
9+
>
10+
<Button floated='right'>I am a floating button</Button>
11+
</Popup>
12+
)
13+
14+
export default PopupVisualFloatingButton
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react'
2+
import { Button, Modal, Popup } from 'semantic-ui-react'
3+
4+
const PopupVisualInsideModal = () => (
5+
<Modal trigger={<Button data-tid='button-dialog'>Open a dialog</Button>}>
6+
<p>This is a dialog</p>
7+
8+
<Popup
9+
data-tid='popup-content'
10+
on='click'
11+
trigger={<Button data-tid='button-popup'>Open a popup</Button>}
12+
>
13+
This is a nested Popup
14+
</Popup>
15+
</Modal>
16+
)
17+
18+
export default PopupVisualInsideModal

0 commit comments

Comments
 (0)