Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow customizing snapshot subdirectory #158

Closed
wants to merge 2 commits into from

Conversation

malykhinvi
Copy link

Basically, this change is a workaround for #61.

Because of the existing behavior of Cypress,cy.screenshot in the Interactive mode puts screenshots in different subdirectories. If you run all specs the screenshot will be nested in 'All Specs' folder, whilst if you run the only spec file, the screenshot will be under the folder of a spec file name.

As this plugin works on top of cypress screenshots but uses its own folder to store snapshots (basically it copy/pastes screenshots to snapshots folder), one of the possible workarounds is to modify the subdirectory of every snapshot. To make it possible, we can pass a callback to plugin options like that:

const { addMatchImageSnapshotPlugin } = require('cypress-image-snapshot/plugin');

module.exports = (on, config) => {
  const getSpecSnapshotFolder = (specScreenshotFolder) => '';
  addMatchImageSnapshotPlugin(on, config, {getSpecSnapshotFolder});
};

If we return an empty string from getSpecSnapshotFolder, that effectively means that no subdirectory needed and all snapshots will be stored in the root of the snapshots folder. Not sure, what happens with spec names collisions though...

@changeset-bot
Copy link

changeset-bot bot commented Jan 30, 2021

⚠️ No Changeset found

Latest commit: 6c288db

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@malykhinvi
Copy link
Author

@jaredpalmer hi! Could you please review and let me know what do you think of this workaround? After I resolved conflicts, I noticed a message from changeset-bot. I'm wondering, who should be changing the content for changelog?

@malykhinvi malykhinvi closed this Aug 31, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant