Skip to content

Instantly share code, notes, and snippets.

@0xIslamTaha
Created April 13, 2020 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xIslamTaha/227b8d143c265eb12e27acdc0ed0a802 to your computer and use it in GitHub Desktop.
Save 0xIslamTaha/227b8d143c265eb12e27acdc0ed0a802 to your computer and use it in GitHub Desktop.
custom matchImageSnapshot command
import { addMatchImageSnapshotCommand } from 'cypress-image-snapshot/command';
const snapshotsFolder = Cypress.config('customSnapshotsDir');
const waitForFirstTime = Cypress.config('waitForFirstTime');
addMatchImageSnapshotCommand();
Cypress.Commands.add(
'waitMatchImageSnapshot',
{
prevSubject: 'optional',
},
(
subject,
snapshotName,
options = {
failureThreshold: 200,
failureThresholdType: 'pixel',
customDiffConfig: { threshold: 0.2 },
retryCounter: 10,
},
) => {
const filePath = `${snapshotsFolder}${Cypress.spec.name}/${snapshotName}.snap.png`;
cy.task('readFileMaybe', filePath).then(result => {
if (!result) {
cy.wait(waitForFirstTime);
}
});
if (subject) {
return cy.wrap(subject).matchImageSnapshot(snapshotName, options);
}
return cy.matchImageSnapshot(snapshotName, options);
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment