meinaart / cypress-plugin-snapshots

Plugin for snapshot tests in Cypress.io
MIT License
489 stars 116 forks source link

(bug) `capture` setting not respected #171

Open vegerot opened 3 years ago

vegerot commented 3 years ago

Describe the bug When running

  it.only('looks right', () => {
    cy.url().should(($url) => {
      expect(new URL($url).toString()).to.equal(new URL(config.dashboardUrl).toString());
    });
    cy.document().toMatchImageSnapshot({ capture: 'runner' });
  });

the option I provide to capture does nothing. It will always use the fullScreen setting, no matter what I do.

To Reproduce Steps to reproduce the behavior:

  1. Write a simple toMatchImageSnapshot test
  2. Try changing the capture setting
  3. notice nothing changes

Expected behavior It should respect the capture setting

Desktop (please complete the following information):

Additional context

Another way to show this is to do something like

  it.only('looks right', () => {
    cy.url().should(($url) => {
      expect(new URL($url).toString()).to.equal(new URL(config.dashboardUrl).toString());
    });
    cy.screenshot({ capture: 'runner' });
    cy.document().toMatchImageSnapshot({ capture: 'runner' });
  });

As you start changing the capture settings to both screenshot and toMatchImageSnapshot, you'll see that the screenshot will update the image to look very different each time, but toMatchImageSnapshot looks identical

vegerot commented 3 years ago

Looking into this more, it gets even weirder. It looks like this bug only happens the FIRST time you open cypress...sometimes.

If I have a line like

    cy.document().toMatchImageSnapshot({ capture: 'runner' });

Then about 50% of the time it will use fullScreen, and the other 50% it will use viewport. I still cannot get runner to work.

vegerot commented 3 years ago

I'm not totally sure, but I think I figured it out (mostly).

Looks like

    cy.document().toMatchImageSnapshot({ screenshotConfig: { capture: 'runner' } });

works.

Related to #152 and #153

vegerot commented 3 years ago

Related to those, please update the types because

image