Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSW-23: Testing with Cypress #51

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

PSW-23: Testing with Cypress #51

wants to merge 13 commits into from

Conversation

osheinonen
Copy link

@osheinonen osheinonen commented Jul 14, 2021

Changes proposed in this PR:

  • End-to-end testing and page specific visual regression testing with Cypress and cypress-image-snapshot
  • Unit testing and component specific visual regression testing with Jest, testing-library, jsdom-screenshot and jest-image-snapshot
  • Updated CircleCI config to include new jobs for dependency installation, caching and testing
  • Added path aliases for Typescript and Jest configs
  • npm scripts updated with testing related scripts
    • "test:jest": "jest"
    • "test:jest:update": "jest --updateSnapshot"
    • "test:cypress:open": "cypress open"
    • "test:cypress:run": "cypress run"
    • "test:cypress:run:update": "cypress run --env updateSnapshots=true"

Note:

  1. There are some type conflict between Cypress and Jest. Those can be resolved with approach described here: https://github.com/cypress-io/cypress-and-jest-typescript-example
  2. All of the testing scripts can be run locally but visual regression image snapshots generated in local machines will be different than those generated in CI (because of different OS and rendering engines). Locally generated image snapshots should never been pushed to version control. Maybe we could disable visual regression tests when test suites are run locally.

How to test:

  1. Checkout to this branch locally
  2. Open welcome.tsx component file (src/components/welcome/welcome.tsx)
  3. Make a change to the rendered component (etc. add additional text)
  4. Push changes and open CircleCI dashboard (https://app.circleci.com/pipelines/github/wunderio/nextjs-project?branch=testing)
  5. Latest pipeline should show failing jest and cypress jobs
  6. Inspect the jobs and their reason for failing
  7. Artifact tab should show diff outputs for failing image snapshots
  8. Download current output images (snapshots/current_output/...), replace old output images with these newly downloaded ones and push them to the version control
  9. Now CircleCI pipeline jobs should all be passing

Link to feature environment:
https://testing.nextjs-project.dev.wdr.io/

@osheinonen osheinonen force-pushed the testing branch 5 times, most recently from f8f16dd to 3f586b6 Compare July 14, 2021 11:37
@osheinonen osheinonen self-assigned this Jul 14, 2021
@osheinonen osheinonen marked this pull request as ready for review July 14, 2021 13:12
- ~/.cache
jest:
docker:
- image: circleci/node:12.16.1-browsers
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could use Node LTS version. v12 is quite old.
There is option to use v14.
https://circleci.com/developer/images/image/cimg/node#image-tags

This reverts commit dc848d6.
@lauriskuznecovs lauriskuznecovs changed the title Testing PSW-23: Testing with Cypress Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants