npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ovotech/cypress-tourist

v1.3.4

Published

Visit a place, take a picture. Compare.

Downloads

27

Readme

Cypress Tourist

PRs Welcome

Take a picture

Visit a place, take a picture. Compare.

Visual Regression tool for Cypress using blink-diff.

Features

  • Separate processes for screenshot and comparing
  • Supports typescript

Directory Structure and concepts

Name | Location | Description | Intent --- | --- | --- | --- champion | cypress/screenshots/champion | Location of the screenshots to be committed to the code-base. | In first place challenger | cypress/screenshots/challenger | Location of the screenshots from the latest cypress run. | Challenging first place diff | cypress/screenshots/diff | Location of the diff'd screenshots. | Differences between the champion and challenger

Ideal Workflow

Below outlines an ideal workflow for integrating visual regression into a project.

  1. The developer makes a code change.
  2. The developer commits and tries to push the code.
  3. The end-to-end test suite runs on the developers machine via a pre-push hook, generating challenger screenshots.
  4. Once the end-to-end test suite completes, the visual regression script is run and challenger and champion screenshots are diff'ed.
  5. 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.
  6. Developer commits the new champion's and tries to push the code again.

The build pipeline would also follow a similar process, failing the build should there be any visual regression the developer inadvertently introduced.

Consider outputting the diff directory as build assets.

Installation

Assuming you already have cypress installed and setup.

npm install --save-dev @ovotech/cypress-tourist

# Alternatively if using yarn
yarn add dev @ovotech/cypress-tourist

Add the script to your package.json

{
    "scripts": {
        "test-visual-regression": "cypress-tourist"
    }
}

For the first time running create the directories seen in the directory structure table above.

Append the following to your .gitignore

cypress/screenshots/*
!cypress/screenshots/champion

Append 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.

*.png binary

Add to your cypress.json file

{
  "screenshotsFolder": "cypress/screenshots/challenger"
}

Then when visiting a place - instead of using the standard cy.visit...

Note: this takes two snapshot's of the app in the default viewports - iphone-6 and macbook-13.

import { visitAndSnap } from '@ovotech/cypress-tourist'

describe('Visual Regression', () => {
  it('captures a screenshot', () => {
    visitAndSnap('http://example.com')
  })
})

Alternatively if snapshotting a UI state change in the app, for example a modal popping up after clicking a button...

Note: this takes a single snapshot of the app in the current viewport and state only

import { snap } from '@ovotech/cypress-tourist'

describe('Visual Regression', () => {
  it('captures a screenshot - in existing state', () => {
    cy.visit('http://example.com')
    cy.find('.modal button').click()

    snap()
  })
})

Running Cypress as you would through your e2e test script, a set of screenshots will be produced in the champion directory.

As a final step run the test-visual-regression script.

npm run test-visual-regression

Your results will be logged to the console.

Possible gotcha's


Development

# Use nvm or node version as per .nvmrc
nvm use

# Install Dependencies
npm install

# Lint files
npm run lint

Deploy

See semver for versioning increments.

# Commit all changes and then on the master branch
npm run bump [major|minor|patch]

Todo

  • [ ] "approve" script to copy new challenger screenshots to champion.
  • [ ] Allow for custom cypress directory - reading from cypress.json.
  • [ ] Automated testing and greenkeeper to maintain latest dependencies.
  • [ ] Different method of waiting for page load - ideally not time based.
  • [ ] Initialize with options such as custom device viewports, or a different wait time.
  • [ ] Investigate only diffing files with a different hash.
  • [ ] Investigate parallel running.
  • [ ] Add docker container runner for screenshots to combat graphics differences.

Contributing

Contributions and PR's welcome.