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 request: mechanism allowing creation of multiple snapshot files from a single test source file #5590

Closed
breathe opened this issue Feb 16, 2018 · 4 comments

Comments

@breathe
Copy link

breathe commented Feb 16, 2018

It would be really powerful if jest were to provide a way to create more than one snapshot from a single test source file ... Sometimes its useful to run the same test suite under 'different conditions' and independently track the evolution of some of the snapshots generated within that test suite.

Some examples of different 'conditions' for which it is sometimes desirable to have multiple snapshots derived from a single test definition ..:

  • some kinds of tests that are expected to produce different results when run in different javascript engines
  • within applications: sometimes its desirable to run a test-suite relative to different versions of an application deployment environment and independently track the changes in those results

It would be nice to be able to:

  1. define a testingDomainSuffix in globalSetup
  2. allow choosing at the call site when executing a test between the normal .toMatchSnapshot and a .toMatchSnapshot(:withinTestingDomain). The :withinTestingDomain variant would choose the snapshot based on the test file and the defined testingDomainSuffix

I'm thinking something along the lines of ...:

in globalSetup:

  • specify the list of all possible testingDomainSuffixes: string[] (to support lifecycle management of stale .snap files)
  • specify the value of testingDomainSuffix for current execution of suite: say "node6" where its enforced that the testingDomainSuffix should belong to the defined list of testingDomainSuffixes expected by the test suite

in foo.test.js
expect({foo: 1}).toMatchSnapshot() <-- current behavior -- diffs against value from snapshot file named foo.test.js.snap

in bar.test.js
expect({bar: 1}).toMatchSnapshot({withinTestingDomain: true}) <-- diffs against value from snapshot file named bar.test.node6.js.snap

@thymikee
Copy link
Collaborator

Check out snapshot-diff, maybe that's enough for your usecase?

@thymikee
Copy link
Collaborator

FYI, we're planning on extending snapshots abilities, see: #5838 (comment). But other than that, we don't want to complicate things too much.

@breathe
Copy link
Author

breathe commented Apr 15, 2018

Thanks for the heads up! I think the feature added in #5838 will address most of my desires/needs.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants