Snapper
Snapper copied to clipboard
Enable changing only the snapshot filename
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.
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.
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?
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
?
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?
Looks promising, I will try it as soon as I find time (hopefully end of the week). Thank you...
Yes, that does the trick for me. Thank you very much :D