verifytests / verify Goto Github PK
View Code? Open in Web Editor NEWVerify is a snapshot tool that simplifies the assertion of complex data models and documents.
License: MIT License
Verify is a snapshot tool that simplifies the assertion of complex data models and documents.
License: MIT License
https://github.com/VerifyTests/Verify/blob/master/docs/converter.md
VerifierSettings.RegisterFileConverter<Image>(
toExtension: "png",
canConvert: target => Equals(target.RawFormat, ImageFormat.Tiff),
conversion: (image, settings) =>
{
var pages = image.GetFrameCount(FrameDimension.Page);
var streams = new List<Stream>();
for (var index = 0; index < pages; index++)
{
image.SelectActiveFrame(FrameDimension.Page, index);
var page = new MemoryStream();
image.Save(page, ImageFormat.Png);
streams.Add(page);
}
return new ConversionResult(
info: new
{
image.PixelFormat,
image.Size
},
streams);
});
VerifierSettings.RegisterFileConverter(
fromExtension: "tif",
toExtension: "png",
conversion: (stream, settings) =>
{
using Image image = Image.FromStream(stream);
var pages = image.GetFrameCount(FrameDimension.Page);
var streams = new List<Stream>();
for (var index = 0; index < pages; index++)
{
image.SelectActiveFrame(FrameDimension.Page, index);
var page = new MemoryStream();
image.Save(page, ImageFormat.Png);
streams.Add(page);
}
return new ConversionResult(
info: new
{
image.PixelFormat,
image.Size
},
streams);
});
VerifierSettings.RegisterFileConverter<Image>(
canConvert: target => Equals(target.RawFormat, ImageFormat.Tiff),
conversion: (image, settings) =>
{
var pages = image.GetFrameCount(FrameDimension.Page);
var streams = new List<ConversionStream>();
for (var index = 0; index < pages; index++)
{
image.SelectActiveFrame(FrameDimension.Page, index);
var page = new MemoryStream();
image.Save(page, ImageFormat.Png);
streams.Add(new ConversionStream("png",page));
}
return new ConversionResult(
info: new
{
image.PixelFormat,
image.Size
},
streams);
});
VerifierSettings.RegisterFileConverter(
fromExtension: "tif",
conversion: (stream, settings) =>
{
using Image image = Image.FromStream(stream);
var pages = image.GetFrameCount(FrameDimension.Page);
var streams = new List<ConversionStream>();
for (var index = 0; index < pages; index++)
{
image.SelectActiveFrame(FrameDimension.Page, index);
var page = new MemoryStream();
image.Save(page, ImageFormat.Png);
streams.Add(new ConversionStream("png",page));
}
return new ConversionResult(
info: new
{
image.PixelFormat,
image.Size
},
streams);
});
@theramis @isidore @michaelstaib @nscheibe @claremacrae
hey peoples. Given our project overlaps i though it might be helpful for us to be aware of each other and have a possible sync so we can share ideas, lessons learnt, code etc.
Some discussion points i can think of
[CallerFilePath]
So would people like to get on a call? or perhaps discuss things here? or some other medium?
Is there anyone else I should have brought in? or tools i should have listed?
I've spent a good 15 mins trying to figure out which api changes the JsonTextWriter.
Also I think if you have something called "Json" then it should be json otherwise make a new format. The problem is you might "think" it looks better but if it's not json then other json based tooling will not work with it.
Also while we're at it where can I find how to change the source directory for all the received files?
Running tests, the comparison tool is launched and the diff clearly shows that the verified vs received are different, but for some reason the tests pass.
Raising for now, will do when I can.
Raising for now, will do when I can.
Full refs on the test project:
Running the test fails.
So my guess is it's choking trying to create the empty verified one, which the stack trace certainly attests to.
C:\Users\Developer\.nuget\packages\emptyfiles\2.0.1\lib\netstandard2.0\EmptyFiles
C:\Users\Developer\.nuget\packages\emptyfiles\2.0.1\lib\netstandard2.0\EmptyFiles.dll
i.e. it's a dll not a folder.
System.TypeInitializationException : The type initializer for 'EmptyFiles.AllFiles' threw an exception.
---- System.IO.DirectoryNotFoundException : Could not find a part of the path 'C:\Users\Developer\.nuget\packages\emptyfiles\2.0.1\lib\netstandard2.0\EmptyFiles'.
Stack Trace:
AllFiles.TryCreateFile(String path, Boolean useEmptyStringForTextFiles) line 209
DiffRunner.Launch(ResolvedDiffTool diffTool, String tempFile, String targetFile) line 79
DiffRunner.Launch(String tempFile, String targetFile) line 65
VerifyEngine.ProcessMissing(StringBuilder builder, FilePair item) line 278
VerifyEngine.ProcessMissing(StringBuilder builder) line 238
VerifyEngine.ThrowIfRequired(String message) line 123
InnerVerifier.Verify(String input, VerifySettings settings) line 25
InnerVerifier.Verify[T](T input, VerifySettings settings) line 43
--- End of stack trace from previous location where exception was thrown ---
----- Inner Stack Trace -----
FileSystemEnumerator`1.CreateDirectoryHandle(String path, Boolean ignoreNotFound)
FileSystemEnumerator`1.ctor(String directory, EnumerationOptions options)
FileSystemEnumerable`1.ctor(String directory, FindTransform transform, EnumerationOptions options)
FileSystemEnumerableFactory.UserFiles(String directory, String expression, EnumerationOptions options)
Directory.InternalEnumeratePaths(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options)
Directory.EnumerateFiles(String path, String searchPattern, SearchOption searchOption)
AllFiles.cctor() line 63
Incoming when I get a moment.
Incoming when I get a moment.
when verifying multiple streams, if the umber of files reduces, the test should fail and the clipboard should contain a command to remove extra files
using nullable attributes from net5
allows diff tools to op out of creating an empty file for comparison purposes
to unblock c# using static
feature
Recent changes wrt to [UsesVerify]
and how Verifier.Verify
(the method) uses [CallerFilePath] string sourceFile = ""
have meant that when upgrading some of my projects the file names generated overlapped each other.
The issue is because when calling Verify from the base class, the CallerFilePath is the base class' file path.
Essentially I had:
[UsesVerify]
public class TestsBase
{
protected async Task UtilityAssertMethod(...)
{
//... A bunch of other assertions / mock verifications, etc.
await Verifier.Verify(actual, settings);
}
protected async Task Some_Theory_Should_Work_Impl(bool someParameter)
{
//...arrange
//...act
settings.UseParameter(someParameter);
await Verifier.Verify(actual, settings);
}
}
public class SomethingTests : TestsBase
{
[Fact]
public async Task Some_Test_Should_Work()
{
// ...arrange
// ...act
base.UtilityAssertMethod(...);
}
[Theory]
[InlineData(true)
public async Task Some_Theory_Should_Work(bool someParameter)
=> await base.Some_Theory_Should_Work_Impl(someParameter);
}
The initial way around it I found was to have the base class define an abstract method for it's utility method to call Verify from:
public abstract Task Verify(string target, VerifySettings settings);
And then each leaf test class actually implement that, so their file path would be used:
public override Task Verify(string target, VerifySettings settings)
=> Verifier.Verify(target, settings);
Potentially another workaround would be to pass that value explicitly, rather than let the runtime pass it through. Here's a dotnetfiddle that seems to show that should work: https://dotnetfiddle.net/BT27ry
But I'd need to supply the full path of the file, and I guess getting that is just as challenging. Actually I could just update my protected async Task UtilityAssertMethod(...)
to accept [CallerFilePath] string callerFilePath = ""
and pass that on to Verify. Will give that a go, as it's a lot cleaner. One issue might be that then the verify assertions on UseParameters
might want that to be a parameter...
Don't really have a solution, was just talking through the issue at the moment, but potentially we can just immediately close this and leave it as an example solution for others.
Two solutions above.
None at this stage.
for multipart namespaces (eg Foo.Bar.Bat
) part of the namespace is being correctly included in the verified file name. Once upgrading to 1.27.0 all existing files, with incorrect names, will be renames to the correct file name.
HTML can change from a raw markup perspective, without changing the semantic meaning of it. Most common is changes to whitespace. This causes tests to break, when they do not need to.
If Verify uses a semantic HTML comparison library, I created AngleSharp Diffing for this exact purpose, instead of just doing text comparison, then tests that uses Verify will be much more stable. There are some additional options that can be used in to modify the diffing, e.g. switch to case insensitive comparison, or ignore certain attributes (generated IDs), that are also very helpful.
I will be happy to help integrate AngleSharp Diffing into Verify. Just let me know if you have any questions.
The context is primarily with the bUnit integration.
Here is a quick sample, that shows how Verify fails a test because of insignificant whitespace, and the bUnit tests passes, because it uses MarkupMatches
to verify the rendered markup, using AngleSharp Diffing.
Inheriting from VerifyBase is no longer required.
Instead use the static Verifier
and add [UsesVerifyAttribute]
to all xunit tests that use Verify
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.