haim-io / cypress-image-diff

Visual regression test with cypress
MIT License
240 stars 62 forks source link

Config "FAILURE_THRESHOLD" did not work #200

Closed Strezzo06 closed 6 months ago

Strezzo06 commented 6 months ago

Now i use version 2.1.3 Cypress v13.0.0

FAILURE_THRESHOLD: 0.1

Screen Shot 2023-12-26 at 1 08 03 PM

Result

Screen Shot 2023-12-26 at 1 07 29 PM

I try to add other config

Screen Shot 2023-12-26 at 1 09 04 PM

It's working

Screen Shot 2023-12-26 at 1 09 34 PM
tamasmagyar commented 6 months ago

I was not able to repro with:

Config file (cypress-image-diff.config.cjs):

const config = {
  ROOT_DIR: '',
  FAILURE_THRESHOLD: 0.07,
  COMPARISON_OPTIONS: { threshold: 0.2 },
  RETRY_OPTIONS: {
    log: true,
    limit: 3,
    timeout: 1000,
    delay: 1000
  },
  JSON_REPORT: {
    OVERWRITE: true,
  }
};
module.exports = config;

Result: image


@Strezzo06 Can you share the smallest amount of code that reproduces the bug? This helps in isolating the specific problem without the complexity of a larger codebase.

I created an initial project which you can configure to repro the bug, thank you in advance for the help! Playground repository: https://github.com/tamasmagyar/cypress-image-diff-repro

Strezzo06 commented 6 months ago

My config file

// cypress-image-diff.config.cjs
const config = {
    ROOT_DIR: '',
    FAILURE_THRESHOLD: 0.1,
    COMPARISON_OPTIONS: { threshold: 0.2 }, // default to { threshold: 0.1 }
    RETRY_OPTIONS: {
        log: true,
        limit: 3, // max number of iterations
        timeout: 15000, // time limit in ms
        delay: 1000, // delay before next iteration, ms
    },
    JSON_REPORT: {
        // FILENAME: 'cypress_visual_report', // default "report_[datetime].json"
        OVERWRITE: true, // default true
    },
};
module.exports = config; 

cypress.config.js

const { defineConfig } = require('cypress');
const getCompareSnapshotsPlugin = require('cypress-image-diff-js/plugin');

module.exports = defineConfig({
    defaultCommandTimeout: 15000,
    viewportWidth: 1440,
    viewportHeight: 900,
    waitForAnimations: true,
    scrollBehavior: 'center',
    e2e: {
        setupNodeEvents(on, config) {
            // // import and initialise the cypress image diff plugin
            getCompareSnapshotsPlugin(on, config);

            //Separate CV/LCV
            if (config.env.WEB === 'lcv') {
                return {
                    specPattern: ['cypress/e2e/lcv/**/product*.cy.js'],
                };
            } else if (config.env.WEB === 'cv') {
                return {
                    specPattern: ['cypress/e2e/cv/**/*.cy.js'],
                };
            }
            return getCompareSnapshotsPlugin(on, config);
        },
        baseUrl: 'http://localhost:3000',
        specPattern: 'cypress/e2e/**/*.{js,jsx,ts,tsx}',
    },
});

I will try to run on cypress 13.6.1 to compare with cypress 13.0.0

Strezzo06 commented 6 months ago

I found the root cause. My problem is this condition that i added before return config

//Separate CV/LCV
            if (config.env.WEB === 'lcv') {
                return {
                    specPattern: ['cypress/e2e/lcv/**/product*.cy.js'],
                };
            } else if (config.env.WEB === 'cv') {
                return {
                    specPattern: ['cypress/e2e/cv/**/*.cy.js'],
                };
            }

When i remove that condition. My config can work properly.

Screen Shot 2023-12-27 at 2 27 09 PM
tamasmagyar commented 6 months ago

Can you try the following changes, please?

I think assigning to config.specPattern should do job, you don't have to return with that.

const { defineConfig } = require('cypress');
const getCompareSnapshotsPlugin = require('cypress-image-diff-js/plugin');

module.exports = defineConfig({
    defaultCommandTimeout: 15000,
    viewportWidth: 1440,
    viewportHeight: 900,
    waitForAnimations: true,
    scrollBehavior: 'center',
    e2e: {
        setupNodeEvents(on, config) {
            //Separate CV/LCV
            if (config.env.WEB === 'lcv') {
                                config.specPattern = 'cypress/e2e/lcv/**/product*.cy.js'
            } else if (config.env.WEB === 'cv') {
                config.specPattern = 'cypress/e2e/cv/**/*.cy.js'
            }
            return getCompareSnapshotsPlugin(on, config);
        },
        baseUrl: 'http://localhost:3000',
        specPattern: 'cypress/e2e/**/*.{js,jsx,ts,tsx}',
    },
});
Strezzo06 commented 6 months ago

Can you try the following changes, please?

I think assigning to config.specPattern should do job, you don't have to return with that.

const { defineConfig } = require('cypress');
const getCompareSnapshotsPlugin = require('cypress-image-diff-js/plugin');

module.exports = defineConfig({
  defaultCommandTimeout: 15000,
  viewportWidth: 1440,
  viewportHeight: 900,
  waitForAnimations: true,
  scrollBehavior: 'center',
  e2e: {
      setupNodeEvents(on, config) {
          //Separate CV/LCV
          if (config.env.WEB === 'lcv') {
                                config.specPattern = 'cypress/e2e/lcv/**/product*.cy.js'
          } else if (config.env.WEB === 'cv') {
              config.specPattern = 'cypress/e2e/cv/**/*.cy.js'
          }
          return getCompareSnapshotsPlugin(on, config);
      },
      baseUrl: 'http://localhost:3000',
      specPattern: 'cypress/e2e/**/*.{js,jsx,ts,tsx}',
  },
});

Thank you so much, it's work.