Snapper icon indicating copy to clipboard operation
Snapper copied to clipboard

Added support for customizing serializer settings

Open SbiCA opened this issue 5 years ago • 3 comments

Use 'ICustomSnapshotSerializerSettings' to implement a custom class in order target different serializer settings for Json storage addresses #79

SbiCA avatar Jan 09 '21 23:01 SbiCA

Not sure if using Customizing Func<JsonSerialzerSettings> like https://github.com/tomasbruckner/jest-dotnet#configuring-serialization would be better since the behaviour highly depends on the test runner but would allow multi configuration. @theramis happy to hear your thoughts 😄

SbiCA avatar Jan 11 '21 12:01 SbiCA

Hey @SbiCA,

Thanks for your PR!

Not sure if using Customizing Func<JsonSerialzerSettings> like https://github.com/tomasbruckner/jest-dotnet#configuring-serialization would be better since the behaviour highly depends on the test runner but would allow multi configuration. @theramis happy to hear your thoughts 😄

I think I prefer the way you have done it over having a static SnapshotSettings class. This way it forces the user to think of it like a global setting. With a static class it can be easy to set a value in test A and then test B would also be affected.

There are two things that are on my mind.

  1. I'm not sure if exposing Newtonsoft.Json is a great idea which makes me reluctant to expose JsonSerializerSettings (see https://github.com/theramis/Snapper/issues/79)
  2. Might be a good idea to rename ICustomSnapshotSerializerSettings -> ISnapperSettings so that the user can customise other things like folder name, file extension etc (this might become a fairly big change)

theramis avatar Jan 12 '21 02:01 theramis

@theramis

  1. I'm not sure if exposing Newtonsoft.Json is a great idea which makes me reluctant to expose JsonSerializerSettings (see #79)

I agree on that but on the other hand I'm not sure If the user actually cares that much (at least on my end I use it in test projects and this would only relate to settings not the public API for the assertion), and on the other hand you could also anticipate that change (to System.Text.Json if you wish to change) by only depending on this Settings class in the Json related parts which would contradict your 2nd point. Since you'd not want to tie even closer to Newtonsoft but rather make it a configuration of JObjectHelper or maybe even inline the usage in JsonSnapshotSanitiser, JsonSnapshotStore and in JsonSnapshotComparer. So TLDR not sure what direction you would like to move?

  1. Might be a good idea to rename ICustomSnapshotSerializerSettings -> ISnapperSettings so that the user can customise other things like folder name, file extension etc (this might become a fairly big change)

Agreed, but also depends on the outcome of the first point

I've update the design slightly to come up with some middle ground solution 😃

SbiCA avatar Jan 12 '21 20:01 SbiCA

Hey @SbiCA ,

Super late reply

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

That essentially does the same as this!

theramis avatar Feb 01 '23 22:02 theramis