Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Feature] Delete obsolete screenshots on update #10

Open
k-g-a opened this issue Sep 24, 2018 · 1 comment
Open

[Feature] Delete obsolete screenshots on update #10

k-g-a opened this issue Sep 24, 2018 · 1 comment

Comments

@k-g-a
Copy link
Contributor

k-g-a commented Sep 24, 2018

Hi!
There is a known limitation in both this addon and jest-image-snapshots: running jest -u won't delete obsolete screenshots.
This is due to fact, that there is no source of information for runner about which screenshots must be used.
One possible solution would be to create such source in form of json file which would be placed in snapshotsDir (default or specified by user). The scturcure of this file would be:

{
  "TEST_NAME_1 COUNTER": {
    "filePath": "PATH_TO_FILE_1",
    "meta": {}
  },
  "TEST_NAME_2 COUNTER": {
    "filePath": "PATH_TO_FILE_2",
    "meta": {}
  }
}

The rest of the logic could be taken from original toMatchSnapshot().

I propose to use testName => {filePath, meta} instead of testName => filePath, so one could store and read additional info in custom matchers by calling:

  import {getMetaFor} from 'jest-screenshots';
  ...
  const myMeta = getMetaFor(this);
  ...
  exprect(target).toMatchImageSnapshot({
    meta?: {...} // any serializable data
  })

Our particular use case is to store enzyme's .html() in meta and compare it with target.html() before taking actual screenshot for comparison. For now we keep all that logic in our custom matcher and it saves plenty of time for non-changed assertions (no need to wait for puppeteer). Another use case could be storing settings (antialiasing/threshholds) or environment (os/browser) used to take screenshot.
It may seem over-complicated at first glance, but actual implementation details would be hidden for most users while other could benefit from it.

If this feature is anticipated I can make a PR.

@kevinbuhmann
Copy link

kevinbuhmann commented Sep 24, 2021

I solved reporting/deleting obsolete screenshot files with patch-package and this patch against version [email protected].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants