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

Enable changing only the snapshot filename #93

Closed
DavidInterad opened this issue Aug 23, 2022 · 6 comments
Closed

Enable changing only the snapshot filename #93

DavidInterad opened this issue Aug 23, 2022 · 6 comments
Labels
enhancement New feature or request

Comments

@DavidInterad
Copy link

Is your feature request related to a problem? Please describe.
Using tests with dynamic data (e.g. DataRow, DynamicData, DataSource) I want to control the filename of the snapshots, so they do not end up overwriting each other. But I do not want to hardcode any file path, just modify the filename.

Describe the solution you'd like
I would like to use SnapshotId to specify the snapshot filename, but setting snapshotDirectory to null so the default location (_snapshots subdirectory) is used.

Describe alternatives you've considered
I am currently using child snapshots instead, which is rather tedious because the snapshots themselves are rather large and there are many data rows.
There could be a way to specify the folder using path variables or getting the path from the test file, but both are rather tedious and undocumented in Snapper.

@DavidInterad DavidInterad added the enhancement New feature or request label Aug 23, 2022
@theramis
Copy link
Owner

Hey @DavidInterad, thanks bringing this up.

The current way of controlling snapshots is definitely a bit tedious. Let me have a think about some ideas and I'll get back to you in about 2 days and then we can go from there.

@theramis
Copy link
Owner

theramis commented Aug 26, 2022

So I had a think about it and what do you think about something like this.

An optional parameter which takes in SnapshotSettings. You can override anything optionally (e.g. directory or the file name etc)

snapshot.ShouldMatchSnapshot(SnapshotSettings.New()
    .SnapshotDirectory("")                         // optional
    .SnapshotFileName("")                         // optional
)

childSnapshot.ShouldMatchChildSnapshot("childSnapshotName", SnapshotSettings.New()
    .SnapshotDirectory("")                         // optional
    .SnapshotFileName("")                         // optional
)

Still need to have a think about how the Storing snapshot per class feature (see this ) would be affected by this though. So this is very much a draft. What do you think?

@DavidInterad
Copy link
Author

This would do the trick for me.
I don't know how this would break stuff for someone using the current SnapshotId class to specify the file location, though.

For storing snapshots per class you could offer the same parameters in the StoreSnapshotsPerClass (directory and file name), and any SnapshotSetting given in the Should... method would override it, I think.
How is StoreSnapshotsPerClass working with giving a directory in SnapshotId?

@theramis
Copy link
Owner

Hey @DavidInterad ,
Sorry it took a bit longer than expected!

Just added Custom Snapshot Settings in the latest version 2.4.0. See the docs here.

That should hopefully solve your issue?

@DavidInterad
Copy link
Author

Looks promising, I will try it as soon as I find time (hopefully end of the week).
Thank you...

@DavidInterad
Copy link
Author

Yes, that does the trick for me. Thank you very much :D

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

No branches or pull requests

2 participants