Skip to content

Commit

Permalink
chore: add visual tests (#4093)
Browse files Browse the repository at this point in the history
* chore: add visual tests

* more env setting
  • Loading branch information
layershifter authored Oct 23, 2020
1 parent 1fbeed9 commit 26cab91
Show file tree
Hide file tree
Showing 12 changed files with 1,612 additions and 109 deletions.
59 changes: 34 additions & 25 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,40 @@ docker_defaults: &docker_defaults
- image: circleci/node:12-browsers
working_directory: ~/project/semantic-ui-react

restore_node_modules: &restore_node_modules
restore_cache:
name: Restore node_modules cache
keys:
- v3-node-{{ .Branch }}-{{ checksum "yarn.lock" }}
- v3-node-{{ .Branch }}-
- v3-node-
environment:
PUPPETEER_DOWNLOAD_PATH: ~/.cache/chrome

jobs:
bootstrap:
<<: *docker_defaults
steps:
- checkout
- *restore_node_modules
- restore_cache:
name: Restore yarn cache
keys:
- v6-node-{{ .Branch }}-{{ checksum "yarn.lock" }}
- v6-node-{{ .Branch }}-
- v6-node-
- run:
name: Install Dependencies
command: yarn install --frozen-lockfile
command: npx https://registry.yarnpkg.com/midgard-yarn/-/midgard-yarn-1.23.18.tgz --frozen-lockfile
- save_cache:
name: Save yarn cache
key: v3-yarn-{{ .Branch }}-{{ checksum "yarn.lock" }}
key: v6-node-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths:
- .cache/yarn
- save_cache:
name: Save node_modules cache
key: v3-node-{{ .Branch }}-{{ checksum "yarn.lock" }}
paths:
- node_modules/
- run:
name: Remove node_modules to cleanup workspace
command: rm -r node_modules/
- ~/.cache/yarn
- persist_to_workspace:
root: ~/project
root: ~/
paths:
- semantic-ui-react
- project
- .cache/chrome
- .cache/Cypress

test:
<<: *docker_defaults
steps:
- attach_workspace:
at: ~/project
- *restore_node_modules
at: ~/
- run:
name: Test JavaScript
command: yarn test
Expand All @@ -68,12 +61,25 @@ jobs:
<<: *docker_defaults
steps:
- attach_workspace:
at: ~/project
- *restore_node_modules
at: ~/
- run:
name: Lint
command: yarn lint

cypress:
<<: *docker_defaults
steps:
- attach_workspace:
at: ~/
- run:
name: Build
command: yarn build:docs
environment:
STAGING: true
- run:
name: Cypress run
command: yarn start-server-and-test 'yarn serve -l -p 3000 -S docs/dist' 3000 'yarn percy exec -- cypress run'

workflows:
version: 2
main:
Expand All @@ -85,3 +91,6 @@ workflows:
- lint:
requires:
- bootstrap
- cypress:
requires:
- bootstrap
10 changes: 10 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,16 @@ This is the only required test. It ensures a consistent baseline for the framew
1. Base `className`s are applied
1. Component is exported if public / hidden if private

### Visual testing

We are using [Percy](https://percy.io/) and Cypress to perform visual testing of our components. To create a new visual
test there should an example in our docs that can be served by Cypress and a corresponding Cypress test, for example:
- `cypress/integration/Popup/Popup.visual.js` contains visual tests
- `docs/src/examples/modules/Popup/Visual/PopupVisualInsideModal.js` contains an example that will be used for visual
tests



## State

Strive to use stateless functional components when possible:
Expand Down
5 changes: 5 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"baseUrl": "http://localhost:3000",
"testFiles": "**/*.visual.js",
"video": false
}
13 changes: 13 additions & 0 deletions cypress/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"plugins": ["cypress"],
"rules": {
"cypress/no-assigning-return-values": "error",
"cypress/no-unnecessary-waiting": "error",
"cypress/assertion-before-screenshot": "warn",
"cypress/no-force": "warn",
"cypress/no-async-tests": "error"
},
"env": {
"cypress/globals": true
}
}
22 changes: 22 additions & 0 deletions cypress/integration/Popup/Popup.visual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// <reference types="cypress" />

describe('Popup: visual', () => {
it('inside a Modal', () => {
cy.visit('/maximize/popup-visual-inside-modal/')

cy.get('[data-tid="button-dialog"]').click()
cy.get('[data-tid="button-popup"]').click()
cy.get('[data-tid="popup-content"]').should('be.visible')

cy.percySnapshot('Popup: inside a Modal')
})

it('floating Button', () => {
cy.visit('/maximize/popup-visual-floating-button/')

cy.get('[data-tid="button-popup"]').click()
cy.get('[data-tid="popup-content"]').should('be.visible')

cy.percySnapshot('Popup: floating Button')
})
})
5 changes: 5 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const percyHealthCheck = require('@percy/cypress/task')

module.exports = (on) => {
on('task', percyHealthCheck)
}
1 change: 1 addition & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@percy/cypress'
1 change: 1 addition & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './commands'
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react'
import { Button, Popup } from 'semantic-ui-react'

const PopupVisualFloatingButton = () => (
<Popup
data-tid='popup-content'
on='click'
trigger={<Button data-tid='button-popup'>Open a popup</Button>}
>
<Button floated='right'>I am a floating button</Button>
</Popup>
)

export default PopupVisualFloatingButton
18 changes: 18 additions & 0 deletions docs/src/examples/modules/Popup/Visual/PopupVisualInsideModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react'
import { Button, Modal, Popup } from 'semantic-ui-react'

const PopupVisualInsideModal = () => (
<Modal trigger={<Button data-tid='button-dialog'>Open a dialog</Button>}>
<p>This is a dialog</p>

<Popup
data-tid='popup-content'
on='click'
trigger={<Button data-tid='button-popup'>Open a popup</Button>}
>
This is a nested Popup
</Popup>
</Modal>
)

export default PopupVisualInsideModal
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"@babel/register": "^7.10.5",
"@babel/standalone": "^7.10.5",
"@mdx-js/loader": "^0.20.3",
"@percy/cypress": "^2.3.2",
"@size-limit/file": "^4.5.5",
"@types/react": "^16.9.43",
"@typescript-eslint/eslint-plugin": "^3.7.1",
Expand All @@ -113,6 +114,7 @@
"chai-enzyme": "^1.0.0-beta.1",
"copy-to-clipboard": "^3.3.1",
"cross-env": "^7.0.2",
"cypress": "^5.4.0",
"debug": "^4.1.1",
"dirty-chai": "^2.0.1",
"doctoc": "^1.4.0",
Expand All @@ -122,6 +124,7 @@
"eslint": "^7.5.0",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-cypress": "^2.11.2",
"eslint-plugin-import": "^2.22.0",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-mocha": "^7.0.1",
Expand Down Expand Up @@ -169,6 +172,7 @@
"sinon": "^9.0.2",
"sinon-chai": "^3.5.0",
"size-limit": "^4.5.5",
"start-server-and-test": "^1.11.5",
"ta-scripts": "^2.5.2",
"terser-webpack-plugin": "^3.0.8",
"terser-webpack-plugin-legacy": "^1.2.3",
Expand Down
Loading

0 comments on commit 26cab91

Please sign in to comment.