jaredpalmer / cypress-image-snapshot

Catch visual regressions in Cypress
MIT License
888 stars 160 forks source link

<svg> snapshots are not working in headless mode #122

Closed louis-vinchon closed 4 years ago

louis-vinchon commented 4 years ago

Using cypres 4.x.x

I have a couple representations in my website that I would love to do visual regression tests on, unfortunately it does not work, I have observed two behaviors:

louis-vinchon commented 4 years ago

Strangely I have an other that works fine. I don't know what's wrong with the other two.

jrfornes commented 1 year ago

For anyone having errors like "RangeError: The argument 'size' is invalid. Received -1051200", take a look at your full page screenshot size - run your tests in interactive mode and see how large your screenshot size is and if it looks clipped, specifically the area you are screenshotting then you might need to increase your full page size. take a look at https://docs.cypress.io/api/plugins/browser-launch-api#See-all-Chrome-browser-switches for guidance on how to do that.

I fixed my errors with the following Cypress configuration:

setupNodeEvents(on, config) {
      on('before:browser:launch', (browser, launchOptions) => {
        if (browser.name === 'chrome' && browser.isHeadless) {
          // set full page screenshot size to 1920x1080
          launchOptions.args.push('--window-size=1920,1080');

          // force screen to be non-retina (to keep 1920x1080 size)
          launchOptions.args.push('--force-device-scale-factor=1');

          // disable shared memory usage (to prevent chrome from crashing)
          launchOptions.args.push('--disable-dev-shm-usage');
        }

        return launchOptions;
      });

      on('task', {
        log(message) {
          console.log(message);
          return null;
        },
      });

      // `on` is used to hook into various events Cypress emits
      // `config` is the resolved Cypress config
      require('@cypress/code-coverage/task')(on, config);

      // implement node event listeners here
      addMatchImageSnapshotPlugin(on, config);

      return config;
},