Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ static void AddPage(PageDescriptor page)
});
}
```
<sup><a href='/src/Tests/Samples.cs#L72-L105' title='Snippet source file'>snippet source</a> | <a href='#snippet-GenerateDocument' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Tests/Samples.cs#L84-L117' title='Snippet source file'>snippet source</a> | <a href='#snippet-GenerateDocument' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down Expand Up @@ -139,6 +139,27 @@ public Task VerifyDocument()
<img src="src/Tests/Samples.VerifyDocument%2300.verified.png" width="300px">


## Exclude the pdf

QuestPDF renders the source pdf, and it is included in the snapshot as a `.verified.pdf`. Generating it is expensive, and committing it is not always wanted. [`ExcludeTargets`](https://github.com/VerifyTests/Verify/blob/main/docs/converter.md#excluding-targets) drops it from a verification and skips the generation, while the rendered pages and info still verify:

<!-- snippet: ExcludePdf -->
<a id='snippet-ExcludePdf'></a>
```cs
[Test]
public Task ExcludePdf()
{
var document = GenerateDocument();
return Verify(document)
.ExcludeTargets("pdf");
}
```
<sup><a href='/src/Tests/Samples.cs#L48-L58' title='Snippet source file'>snippet source</a> | <a href='#snippet-ExcludePdf' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

To exclude the pdf for every test, call `VerifierSettings.ExcludeTargets("pdf")` at initialization.


## PagesToInclude

To render only a defined number of pages at the start of a document:
Expand All @@ -154,7 +175,7 @@ public Task PagesToInclude()
.PagesToInclude(1);
}
```
<sup><a href='/src/Tests/Samples.cs#L48-L58' title='Snippet source file'>snippet source</a> | <a href='#snippet-PagesToInclude' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Tests/Samples.cs#L60-L70' title='Snippet source file'>snippet source</a> | <a href='#snippet-PagesToInclude' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand All @@ -173,5 +194,5 @@ public Task PagesToIncludeDynamic()
.PagesToInclude(pageNumber => pageNumber == 2);
}
```
<sup><a href='/src/Tests/Samples.cs#L60-L70' title='Snippet source file'>snippet source</a> | <a href='#snippet-PagesToIncludeDynamic' title='Start of snippet'>anchor</a></sup>
<sup><a href='/src/Tests/Samples.cs#L72-L82' title='Snippet source file'>snippet source</a> | <a href='#snippet-PagesToIncludeDynamic' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project>
<PropertyGroup>
<NoWarn>CS1591;CS0649;NU1608;NU1109</NoWarn>
<Version>2.6.0</Version>
<Version>2.7.0</Version>
<AssemblyVersion>1.0.0</AssemblyVersion>
<LangVersion>preview</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
6 changes: 3 additions & 3 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
<PackageVersion Include="Polyfill" Version="10.11.2" />
<PackageVersion Include="ProjectDefaults" Version="1.0.174" />
<PackageVersion Include="QuestPDF" Version="2026.7.0" />
<PackageVersion Include="Verify" Version="31.22.0" />
<PackageVersion Include="Verify" Version="31.24.0" />
<PackageVersion Include="Verify.DiffPlex" Version="3.3.0" />
<PackageVersion Include="Verify.NUnit" Version="31.22.0" />
<PackageVersion Include="Verify.NUnit" Version="31.24.0" />
<PackageVersion Include="Microsoft.Sbom.Targets" Version="4.1.5" />
<PackageVersion Include="Argon" Version="0.35.0" />
<PackageVersion Include="DiffEngine" Version="19.3.1" />
<PackageVersion Include="DiffEngine" Version="19.3.2" />
<PackageVersion Include="EmptyFiles" Version="8.18.2" />
<PackageVersion Include="SimpleInfoName" Version="3.2.0" />
</ItemGroup>
Expand Down
Binary file added src/Tests/Samples.ExcludePdf#00.verified.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/Tests/Samples.ExcludePdf#01.verified.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/Tests/Samples.ExcludePdf.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
Pages: 2,
Settings: {
ContentDirection: LeftToRight,
PDFA_Conformance: None,
PDFUA_Conformance: None,
ImageCompressionQuality: High,
ImageRasterDpi: 288
}
}
12 changes: 12 additions & 0 deletions src/Tests/Samples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ public Task VerifyDocumentWithMetadata()

#endregion

#region ExcludePdf

[Test]
public Task ExcludePdf()
{
var document = GenerateDocument();
return Verify(document)
.ExcludeTargets("pdf");
}

#endregion

#region PagesToInclude

[Test]
Expand Down
25 changes: 14 additions & 11 deletions src/Verify.QuestPDF/VerifyQuestPdf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,23 @@ public static void Initialize()
pagesToInclude = _ => true;
}
// QuestPDF stamps DateTimeOffset.Now into the PDF CreationDate/ModifiedDate on
// every generation. Pin them to a fixed value so the pdf target is byte-stable.
// every generation. Pin them to a fixed value so the pdf target and the info are stable.
var metadata = document.GetMetadata();
metadata.CreationDate = deterministicDate;
metadata.ModifiedDate = deterministicDate;
// The pdf snapshot is always the full document, regardless of PagesToInclude:
// PagesToInclude only trims the rendered png pages below.
var pdf = document.GeneratePdf();
List<Target> targets =
[
new("pdf", new MemoryStream(pdf), performConversion:false)
{
BypassComparersForSubsequentOnDifference = true
}
];
List<Target> targets = [];
// Generating the pdf is expensive, so skip it entirely when the pdf target is excluded.
// The rendered pages and info are unaffected. The pdf snapshot is always the full
// document, regardless of PagesToInclude: PagesToInclude only trims the png pages below.
if (!settings.IsTargetExcluded("pdf"))
{
var pdf = document.GeneratePdf();
targets.Add(
new("pdf", new MemoryStream(pdf), performConversion: false)
{
BypassComparersForSubsequentOnDifference = true
});
}

for (var index = 0; index < pages.Count; index++)
{
Expand Down
Loading