Verify icon indicating copy to clipboard operation
Verify copied to clipboard

Custom verified file suffix and option to use same file name but different extension per test

Open Respectal opened this issue 1 year ago • 3 comments

Situation

We have a big project with a thousand tests and a few thousand approved files. We previously used ApprovalTests and migrated to VerifyTests.

Problems

  1. Changing from .approved. to .verified. will cause a lot of conflicts and changes that we are trying to avoid.
  2. We have tests that use the same name but have different extensions but in VerifyTests it's not possible because the search for verified files does not include an extension (Verify considers another file with a different extension as an excess file).

Proposed solution

  1. Global setting to set the custom suffix instead of '.verified.'.
  2. Setting that is possible to set per test using a specific extension otherwise searching for all verified files.

I'm more than happy to create PR for this if this request is acknowledged and agreed.

Respectal avatar Jul 01 '24 09:07 Respectal

We have tests that use the same name but have different extensions but in VerifyTests it's not possible because the search for verified files does not include an extension (Verify considers another file with a different extension as an excess file).

can you share some example tests for this scenario?

SimonCropp avatar Jul 01 '24 11:07 SimonCropp

We have tests that use the same name but have different extensions but in VerifyTests it's not possible because the search for verified files does not include an extension (Verify considers another file with a different extension as an excess file).

can you share some example tests for this scenario?

This is an example unit test for such scenario.

   [Fact]
   public async Task SameFileNameButDifferentExtension()
   {
       VerifierSettings.DisableRequireUniquePrefix();
       await Verify(
           new[]
           {
               new Target("txt", "data one", "sameName")
           });

       await Verify(
           new[]
           {
               new Target("json", "data two", "sameName")
           });
   }

Respectal avatar Jul 01 '24 12:07 Respectal

try this instead

 public async Task TheTest()
    {
        await Verify(
            new[]
            {
                new Target("txt", "data one", "sameName"),
                new Target("json", "data two", "sameName")
            });
    }

SimonCropp avatar Jul 01 '24 23:07 SimonCropp

So about the second problem: we do not have many of those tests so we will make the test name unique. But what about the first problem: should I provide PR for that global setting?

Respectal avatar Jul 03 '24 13:07 Respectal

Changing from .approved. to .verified. will cause a lot of conflicts and changes that we are trying to avoid.

re the conflicts, i dont understand how there would be any

re the changes. why is this a problem it is a once off change, and then you move forward. it is also a trivial change to make given you can bulk approve the new files

SimonCropp avatar Jul 03 '24 21:07 SimonCropp