/examples/visual-testing-with-percy/README.md

https://github.com/bahmutov/cypress-react-unit-test · Markdown · 58 lines · 40 code · 18 blank · 0 comment · 0 complexity · fa1dac6ddc0ca211d8e77b776ee38842 MD5 · raw file

  1. # example: visual-testing [![This project is using Percy.io for visual regression testing.](https://percy.io/static/images/percy-badge.svg)](https://percy.io/bahmutov/cypress-react-unit-test)
  2. > 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.
  3. ## Usage
  4. 1. Make sure the root project has been built .
  5. ```bash
  6. # in the root of the project
  7. npm install
  8. npm run build
  9. ```
  10. 2. Run `npm install` in this folder to symlink the `cypress-react-unit-test` dependency.
  11. ```bash
  12. # in this folder
  13. npm install
  14. ```
  15. 3. Start Cypress
  16. ```bash
  17. npm run cy:open
  18. # or just run headless tests
  19. npm test
  20. ```
  21. ## Notes
  22. 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.
  23. ```js
  24. mount(<MaterialUIPickers />)
  25. // confirm the DOM has rendered the widget
  26. cy.get('#date-picker-inline').should('have.value', '08/18/2014')
  27. // then take visual snapshot
  28. cy.percySnapshot('Datepicker initial')
  29. cy.get('button[aria-label="change date"]').click()
  30. // confirm the DOM has rendered the widget
  31. cy.get('.MuiPickersBasePicker-container').should('be.visible')
  32. // then take visual snapshot
  33. cy.percySnapshot('Datepicker opened')
  34. ```
  35. ### New screenshot
  36. ![Percy dashboard](images/new-image.png)
  37. ### Visual change
  38. If a pull request introduces visual changes, they are caught and shown as a diff
  39. ![Visual change](images/diff.gif)
  40. **Tip:** you can use any [visual testing](https://on.cypress.io/visual-testing) plugin with component testing.