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

Save snapshots in a folder at the same level of test files #1603

Closed
maxgallo opened this issue Nov 29, 2017 · 3 comments
Closed

Save snapshots in a folder at the same level of test files #1603

maxgallo opened this issue Nov 29, 2017 · 3 comments

Comments

@maxgallo
Copy link

Description

I would like to save the snapshots files inside a folder where the test file is.

Example

This is a classic React component folder structure of what I'd like to have:

└── MenuComponent/
   ├── MenuComponent.js
   ├── MenuComponent.test.js
   ├── menu-component.css
   └── snapshots
       ├── MenuComponent.test.js.md
       └── MenuComponent.test.js.snap

Which are the current options?

Right now I only have two options, but none of them fits our need.

  1. Having all the *.js.md and *.js.snap files inside the MenuComponent folder
  2. Use snapshotDir options to have *.js.md and *.js.snap files inside another root folder.

Use case

We like to have components separated per folder and almost everything, tests included, related to that component is in that folder.

Sometimes we have also sub-components (components that are going to be used only in that component) inside a component folder, so that folder is not always nice an clean like the one in the example.

Since *.js.md and *.js.snap are generated file, they do not require much human interaction. We'd like to have them separated from the files where an human interaction is required.

Solution

We'd like to add a configuration parameter called snapshotLocalDir where you can specify the name of the folder you want to use.

In the example above that name would be snapshots.

Actions

I'm more than happy to create a PR for this one, if you guys think it's a good idea.

@novemberborn
Copy link
Member

Interesting. Leaving them in the same directory as the test file was an intentional decision. The tradeoffs are tricky here, and what you're trying to accomplish seems reasonable to me.

I'm curious what other snapshot users think though.

Lest we add yet another configuration option, perhaps we can support a special pattern in the snapshotDir configuration. If the value starts with */ it's considered relative to the directory that contains the test file. So for your use case you'd specify */snapshots. All other values would follow the current behavior.

@maxgallo
Copy link
Author

I'm happy re-using the same configuration option, but I personally would avoid the */ since it's too much related with the Glob syntax.
What about something more explicit like TEST_FILE_FOLDER (with some prefix/suffix), used in the same way you proposed?

@ajafff
Copy link
Contributor

ajafff commented Jan 7, 2018

I'm looking for a similar feature.
My tests are located at test/api/*.spec.js
I already have a snapshot directory called baselines that's also used by other tests.
Now I want to save my snapshots there using --snapshot-dir baselines. Unfortunately that creates baselines/test/api/*.spec.js.snap while I would prefer baselines/api/*.spec.js.snap.
Long story short: I'd like to be able to replace test/ with baselines/ and leave everything else the same.

I see that this is very hard to do right for everyone while still maintaining an understandable configuration. I just wanted to share my use case.

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

No branches or pull requests

3 participants