-
-
Notifications
You must be signed in to change notification settings - Fork 144
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
Allow file extension to be part of the unique snapshot check #1081
Comments
can you instead use this approach>
|
I tried this in my test suite and face the same problem. It appears to be a race condition based on what happens before each Verify call. I had some async work reading from Azure Storage inside async helper methods that at the end call Verify. There appears to be some sync setup in the Verify task. If any of this is interleaved then the behavior is inconsistent. I'll confirm this theory by switching the order of the Verify calls and the subsequent awaits. |
Oh, I misread your suggestion (I saw that as the |
Yes that works. This test I added in my PR then modified passes: [Fact]
public async Task MultipleExtensions()
{
#region UniqueForFileExtension
await Verify(new[]
{
new Target("txt", "the text"),
new Target("xml", "<a>b</a>"),
}).AutoVerify();
#endregion
Assert.True(File.Exists(CurrentFile.Relative($"Tests.{nameof(MultipleExtensions)}.verified.xml")), "The xml snapshot should exist.");
Assert.True(File.Exists(CurrentFile.Relative($"Tests.{nameof(MultipleExtensions)}.verified.txt")), "The txt snapshot should exist.");
} I'll go give it a try in NuGet Insights and see how it shakes out with helper methods. |
i usually push back on people using multiple Verify calls in the same test. since it means u often need to run the test multiple times to get all the snapshots to be created |
Makes sense. I think it's a bit of a challenge for migration since you want to treat a verify call like an assert. And having multiple asserts per test is very common. Sure, sometimes N asserts map to a single verify as part of the snapshot but in my case it means I have to collect a bunch of Target instances and then call a single verify. I haven't had a chance to iron it out completely but I think it'll work. It's just a shift in test infra from simple asserts nested in helper methods to returning Targets to a single Verify directly in the test method. |
yeah usually that is mitigated by the fact that Verify supports anon objects. https://github.com/VerifyTests/Verify/blob/main/docs/anonymous-types.md |
I tried out a flow where I have an
I felt like the approach I had before where I had multiple |
How could you use that approach when one of the snapshots is JSON (for which you'd normally use |
This should very much be allowed IMO. Surprised to find out it isn't. |
@aradalvand please share a minimal repo of what you want to achieve in a GH repository |
closing this one. I suggest instead you submit a PR that meets your requirements with a single Verify call |
Describe the bug
Verify acts in a strange way when there are two
Verify
calls with the same snapshot prefix but a different file extension. I was expecting file extension to be part of the "identity" of the snapshot file (as the file system would allow) but this appears to not be the case. The snapshot gets renamed based on whicheverVerify(..., extension: "csv or json")
goes last.Apologies if this should be a feature request instead of a bug report. It feels buggy to me but that's perhaps just due to a bad expectation on my part.
I ran into this because I have a JSON file called
..._PackageReadmes.verified.json
and a CSV called..._PackageReadmes.verified.csv
in the same test file. It ran into this problem.Minimal Repro
Submit a PR that fixes the bug
TODO. I will work on this now. I think I will try adding an option
IncludeExtensionInUniquePrefix
to take the stance that this is by design instead of a bug. Let me know if that's the wrong direction.The text was updated successfully, but these errors were encountered: