{"id":22725382,"url":"https://github.com/ovotech/cypress-tourist","last_synced_at":"2025-04-13T20:27:06.011Z","repository":{"id":34984134,"uuid":"194245051","full_name":"ovotech/cypress-tourist","owner":"ovotech","description":"Visit a place, take a picture. Compare.","archived":false,"fork":false,"pushed_at":"2023-07-12T00:12:55.000Z","size":607,"stargazers_count":5,"open_issues_count":13,"forks_count":0,"subscribers_count":18,"default_branch":"master","last_synced_at":"2024-12-05T16:12:13.264Z","etag":null,"topics":["blink-diff","cypress","cypress-io","e2e-testing","testing","visual-regression","visual-regression-testing"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/@ovotech/cypress-tourist","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ovotech.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-28T09:19:22.000Z","updated_at":"2023-04-20T14:43:37.000Z","dependencies_parsed_at":"2024-10-30T12:43:45.638Z","dependency_job_id":null,"html_url":"https://github.com/ovotech/cypress-tourist","commit_stats":{"total_commits":48,"total_committers":2,"mean_commits":24.0,"dds":0.02083333333333337,"last_synced_commit":"7e9a1d549983b2aafcb7581f67092be08b285990"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovotech%2Fcypress-tourist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovotech%2Fcypress-tourist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovotech%2Fcypress-tourist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ovotech%2Fcypress-tourist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ovotech","download_url":"https://codeload.github.com/ovotech/cypress-tourist/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229089207,"owners_count":18018390,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blink-diff","cypress","cypress-io","e2e-testing","testing","visual-regression","visual-regression-testing"],"created_at":"2024-12-10T16:09:48.629Z","updated_at":"2024-12-10T16:09:49.220Z","avatar_url":"https://github.com/ovotech.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cypress Tourist\n\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)\n\n![Take a picture](https://media.giphy.com/media/j5E9vHJSjBcDTXe4E4/source.gif)\n\nVisit a place, take a picture. Compare.\n\nVisual Regression tool for [Cypress] using [blink-diff].\n\n## Features\n\n- Separate processes for screenshot and comparing\n- Supports typescript\n\n## Directory Structure and concepts\n\nName | Location | Description | Intent\n--- | --- | --- | ---\nchampion | cypress/screenshots/champion | Location of the screenshots to be committed to the code-base. | In first place\nchallenger | cypress/screenshots/challenger | Location of the screenshots from the latest cypress run. | Challenging first place\ndiff | cypress/screenshots/diff | Location of the diff'd screenshots. | Differences between the champion and challenger\n\n## Ideal Workflow\n\nBelow outlines an ideal workflow for integrating visual regression into a project.\n\n1. The developer makes a code change.\n1. The developer commits and tries to push the code.\n1. The end-to-end test suite runs on the developers machine via a [pre-push hook], generating `challenger` screenshots.\n1. Once the end-to-end test suite completes, the visual regression script is run and `challenger` and `champion` screenshots are diff'ed.\n1. Differences are flagged in the `diff` directory and the developer either approves by copying the `challenger` screenshot to the `champion` directory, or fixes the issues raised.\n1. Developer commits the new `champion`'s and tries to push the code again.\n\nThe build pipeline would also follow a similar process, failing the build should there be any visual regression the developer inadvertently introduced.\n\nConsider outputting the `diff` directory as build assets.\n\n## Installation\n\nAssuming you already have [cypress] installed and setup. \n\n```sh\nnpm install --save-dev @ovotech/cypress-tourist\n\n# Alternatively if using yarn\nyarn add dev @ovotech/cypress-tourist\n```\n\nAdd the script to your `package.json`\n\n```json\n{\n    \"scripts\": {\n        \"test-visual-regression\": \"cypress-tourist\"\n    }\n}\n```\n\nFor the first time running create the directories seen in the directory structure table above.\n\nAppend the following to your `.gitignore`\n\n```\ncypress/screenshots/*\n!cypress/screenshots/champion\n```\n\nAppend the following to your `.gitattributes` file - or create one if it doesn't exist. This prevents git diff'ing the image binaries and storing the deltas - bloating the repo size.\n\n```\n*.png binary\n```\n\nAdd to your `cypress.json` file\n\n```json\n{\n  \"screenshotsFolder\": \"cypress/screenshots/challenger\"\n}\n```\n\nThen when visiting a place - instead of using the standard `cy.visit`...\n\n**Note:** this takes two snapshot's of the app in the default viewports - `iphone-6` and `macbook-13`.\n\n```js\nimport { visitAndSnap } from '@ovotech/cypress-tourist'\n\ndescribe('Visual Regression', () =\u003e {\n  it('captures a screenshot', () =\u003e {\n    visitAndSnap('http://example.com')\n  })\n})\n```\n\nAlternatively if snapshotting a UI state change in the app, for example a modal popping up after clicking a button...\n\n**Note:** this takes a single snapshot of the app in the current viewport and state only\n\n```js\nimport { snap } from '@ovotech/cypress-tourist'\n\ndescribe('Visual Regression', () =\u003e {\n  it('captures a screenshot - in existing state', () =\u003e {\n    cy.visit('http://example.com')\n    cy.find('.modal button').click()\n\n    snap()\n  })\n})\n```\n\nRunning Cypress as you would through your e2e test script, a set of screenshots will be produced in the `champion` directory.\n\nAs a final step run the `test-visual-regression` script.\n\n```sh\nnpm run test-visual-regression\n```\n\nYour results will be logged to the console.\n\n## Possible gotcha's\n\n- Ensure you've stubbed out [dynamic data and fetches] and [times and dates].\n- Items such as [Sticky headers will need to be hidden or fixed] when capturing screenshots.\n- Ensure [Cypress trashes the challenger folder before it runs] - thanks [@shukii](https://github.com/shukii)\n\n    If this is an issue you can remove the challenger directory after the visual regression run\n\n    ```json\n    {\n        \"scripts\": {\n            \"test-visual-regression\": \"cypress-tourist \u0026\u0026 rimraf cypress/screenshots/challenger\"\n        }\n    }\n    ```\n\n---\n\n## Development\n\n```sh\n# Use nvm or node version as per .nvmrc\nnvm use\n\n# Install Dependencies\nnpm install\n\n# Lint files\nnpm run lint\n```\n\n## Deploy\n\nSee [semver] for versioning increments.\n\n```sh\n# Commit all changes and then on the master branch\nnpm run bump [major|minor|patch]\n```\n\n## Todo\n\n- [ ] \"approve\" script to copy new challenger screenshots to champion.\n- [ ] Allow for custom cypress directory - reading from cypress.json.\n- [ ] Automated testing and greenkeeper to maintain latest dependencies.\n- [ ] Different method of waiting for page load - ideally not time based.\n- [ ] Initialize with options such as custom device viewports, or a different wait time.\n- [ ] Investigate only diffing files with a different hash.\n- [ ] Investigate parallel running.\n- [ ] Add docker container runner for screenshots to combat graphics differences.\n\n## Contributing\n\nContributions and PR's welcome.\n\n\u003c!-- MARKDOWN REFERENCES --\u003e\n\n[blink-diff]: https://github.com/yahoo/blink-diff\n[cypress]: https://www.cypress.io/\n[dynamic data and fetches]: https://docs.cypress.io/guides/guides/network-requests.html#Testing-Strategies\n[pre-push hook]: https://github.com/typicode/husky\n[semver]: https://semver.org/\n[Sticky headers will need to be hidden or fixed]: https://docs.cypress.io/api/commands/screenshot.html#Full-page-captures-and-fixed-sticky-elements\n[times and dates]: https://docs.cypress.io/api/commands/clock.html#Syntax\n[Cypress trashes the challenger folder before it runs]: https://docs.cypress.io/guides/references/configuration.html#Screenshots","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fovotech%2Fcypress-tourist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fovotech%2Fcypress-tourist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fovotech%2Fcypress-tourist/lists"}