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

Configuring Cypres-image-snapshot for Cross-Device Consistency #270

Open
GeetanshuGulati opened this issue Jun 1, 2024 · 1 comment
Open

Comments

@GeetanshuGulati
Copy link

GeetanshuGulati commented Jun 1, 2024

We're newly integrating Cypress into our project for component testing and have also integrated a snapshot testing plugin for our UI components. However, when I run snapshot testing, it's failing even though the snapshots appear visually identical.

I suspect this might be due to the DPI (Dots Per Inch) settings being different between the devices where the initial snapshots were taken and where the tests are currently running.

What configuration settings can we adjust in Cypress to ensure snapshots are taken that are identical across all devices?

command.ts file:

import { addMatchImageSnapshotCommand } from 'cypress-image-snapshot/command;

addMatchImageSnapshotCommand({
  failureThreshold: 0.0,
  failureThresholdType: 'percent',
});

cypress.config file:

import { defineConfig } from 'cypress';
import { addMatchImageSnapshotPlugin } from 'cypress-image-snapshot/plugin';

export default defineConfig({
  component: {
    devServer: {
      framework: 'react',
      bundler: 'webpack',
    },
    setupNodeEvents(on) {
      addMatchImageSnapshotPlugin(on);
    },
  },
});

snapshot taken by
cy.matchImageSnapshot(image-name)

image

@GeetanshuGulati GeetanshuGulati changed the title Snapshot failing for image having no difference Configuring Cypres-image-snapshot for Cross-Device Consistency Jun 1, 2024
@simonsmith
Copy link

Simplest way to solve this is to run your Cypress tests in a Docker container to ensure consistency across platforms. This extends to things like inputs, fonts etc across different platforms.

You will struggle to generate snapshots on a Mac and then run the tests on a Linux OS on a CI machine for example

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

No branches or pull requests

2 participants