martinothamar / Mediator

A high performance implementation of Mediator pattern in .NET using source generators.
MIT License
2.16k stars 71 forks source link

feat: add snapshot tests #122

Closed TimothyMakkison closed 11 months ago

TimothyMakkison commented 1 year ago

Added snapshot tests to detect changes in logic and formatting.

martinothamar commented 1 year ago

You are on fire :fire: I've never worked with snapshot tests before, what's the workflow like when these are added? If we make a change to the generated output (that we want), how do you update the snapshots?

TimothyMakkison commented 1 year ago

I've never worked with snapshot tests before, what's the workflow like when these are added? If we make a change to the generated output (that we want), how do you update the snapshots?

Verify will compare the generated files to the equivalent verified.cs file in the _snapshots folder. Any differences will result in the test failing and causes a difftool to run. Accepting or rejecting the changes has the workflow same as using git. In my case a new window pops up using either the VSCode or Rider difftool. Try chaging Mediator.sbn-cs and running the tests to see how it works on your machine.

Example

image

what's the workflow like when these are added?

Imo it makes playing around with code generation a lot easier 😄. I've used this in a separate branch to remove unneeded blank space. I personally check the difftool and the use an extension to accept all changes.

I considered combining this with the SamplesTests WDYT?

martinothamar commented 11 months ago

Finally tested this out, yep I love it, really useful and simple to use aswell. Thanks! :pray:

I considered combining this with the SamplesTests WDYT?

Yes I think thats a good idea, so that when we add new samples we get both snapshot testing and diagnostics checking in one go.

I'll merge this for now, but feel free follow up with that if you have the time