From 88cee68bee97dc74c408219ff09836fa2e75c2a1 Mon Sep 17 00:00:00 2001 From: Brandon Williams <135203+mbrandonw@users.noreply.github.com> Date: Sat, 11 Sep 2021 15:12:11 -0400 Subject: [PATCH] Save HTML snapshots with .html extension. (#447) This is a small thing I noticed while browsing the code. If you save the snapshots with the `html` extension then you can make it easy to see preview the actual html in a browser locally. * Save HTML snapshots with .html extension. * Apply suggestions from code review Co-authored-by: Max Desiatov --- .../TokamakStaticHTMLTests/HTMLStrategy.swift | 22 +++++++++++++++++++ Tests/TokamakStaticHTMLTests/HTMLTests.swift | 14 ++++++------ ...FontStacks.1.txt => testFontStacks.1.html} | 0 ...FontStacks.2.txt => testFontStacks.2.html} | 0 ...nitizer.1.txt => testHTMLSanitizer.1.html} | 0 ...nitizer.2.txt => testHTMLSanitizer.2.html} | 0 ...testOptional.1.txt => testOptional.1.html} | 0 ...gFusion.1.txt => testPaddingFusion.1.html} | 0 ...gFusion.2.txt => testPaddingFusion.2.html} | 0 9 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 Tests/TokamakStaticHTMLTests/HTMLStrategy.swift rename Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/{testFontStacks.1.txt => testFontStacks.1.html} (100%) rename Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/{testFontStacks.2.txt => testFontStacks.2.html} (100%) rename Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/{testHTMLSanitizer.1.txt => testHTMLSanitizer.1.html} (100%) rename Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/{testHTMLSanitizer.2.txt => testHTMLSanitizer.2.html} (100%) rename Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/{testOptional.1.txt => testOptional.1.html} (100%) rename Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/{testPaddingFusion.1.txt => testPaddingFusion.1.html} (100%) rename Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/{testPaddingFusion.2.txt => testPaddingFusion.2.html} (100%) diff --git a/Tests/TokamakStaticHTMLTests/HTMLStrategy.swift b/Tests/TokamakStaticHTMLTests/HTMLStrategy.swift new file mode 100644 index 00000000..4714eb79 --- /dev/null +++ b/Tests/TokamakStaticHTMLTests/HTMLStrategy.swift @@ -0,0 +1,22 @@ +// Copyright 2021 Tokamak contributors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#if canImport(SnapshotTesting) +import SnapshotTesting + +extension Snapshotting where Value == String, Format == String { + public static let html = Snapshotting(pathExtension: "html", diffing: .lines) +} + +#endif diff --git a/Tests/TokamakStaticHTMLTests/HTMLTests.swift b/Tests/TokamakStaticHTMLTests/HTMLTests.swift index 47847bb3..724986ed 100644 --- a/Tests/TokamakStaticHTMLTests/HTMLTests.swift +++ b/Tests/TokamakStaticHTMLTests/HTMLTests.swift @@ -44,7 +44,7 @@ final class HTMLTests: XCTestCase { let resultingHTML = StaticHTMLRenderer(OptionalBody(model: Model(color: Color.red))) .render(shouldSortAttributes: true) - assertSnapshot(matching: resultingHTML, as: .lines) + assertSnapshot(matching: resultingHTML, as: .html) } func testPaddingFusion() { @@ -52,13 +52,13 @@ final class HTMLTests: XCTestCase { Color.red.padding(10).padding(20) ).render(shouldSortAttributes: true) - assertSnapshot(matching: nestedTwice, as: .lines) + assertSnapshot(matching: nestedTwice, as: .html) let nestedThrice = StaticHTMLRenderer( Color.red.padding(20).padding(20).padding(20) ).render(shouldSortAttributes: true) - assertSnapshot(matching: nestedThrice, as: .lines) + assertSnapshot(matching: nestedThrice, as: .html) } func testFontStacks() { @@ -67,7 +67,7 @@ final class HTMLTests: XCTestCase { .font(.custom("Marker Felt", size: 17)) ).render(shouldSortAttributes: true) - assertSnapshot(matching: customFont, as: .lines) + assertSnapshot(matching: customFont, as: .html) let fallbackFont = StaticHTMLRenderer( VStack { @@ -77,7 +77,7 @@ final class HTMLTests: XCTestCase { .font(.system(.body, design: .serif)) ).render(shouldSortAttributes: true) - assertSnapshot(matching: fallbackFont, as: .lines) + assertSnapshot(matching: fallbackFont, as: .html) } func testHTMLSanitizer() { @@ -85,12 +85,12 @@ final class HTMLTests: XCTestCase { let sanitizedHTML = StaticHTMLRenderer(Text(text)) .render(shouldSortAttributes: true) - assertSnapshot(matching: sanitizedHTML, as: .lines) + assertSnapshot(matching: sanitizedHTML, as: .html) let insecureHTML = StaticHTMLRenderer(Text(text)._domTextSanitizer(Sanitizers.HTML.insecure)) .render(shouldSortAttributes: true) - assertSnapshot(matching: insecureHTML, as: .lines) + assertSnapshot(matching: insecureHTML, as: .html) } } diff --git a/Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testFontStacks.1.txt b/Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testFontStacks.1.html similarity index 100% rename from Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testFontStacks.1.txt rename to Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testFontStacks.1.html diff --git a/Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testFontStacks.2.txt b/Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testFontStacks.2.html similarity index 100% rename from Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testFontStacks.2.txt rename to Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testFontStacks.2.html diff --git a/Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testHTMLSanitizer.1.txt b/Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testHTMLSanitizer.1.html similarity index 100% rename from Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testHTMLSanitizer.1.txt rename to Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testHTMLSanitizer.1.html diff --git a/Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testHTMLSanitizer.2.txt b/Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testHTMLSanitizer.2.html similarity index 100% rename from Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testHTMLSanitizer.2.txt rename to Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testHTMLSanitizer.2.html diff --git a/Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testOptional.1.txt b/Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testOptional.1.html similarity index 100% rename from Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testOptional.1.txt rename to Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testOptional.1.html diff --git a/Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testPaddingFusion.1.txt b/Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testPaddingFusion.1.html similarity index 100% rename from Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testPaddingFusion.1.txt rename to Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testPaddingFusion.1.html diff --git a/Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testPaddingFusion.2.txt b/Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testPaddingFusion.2.html similarity index 100% rename from Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testPaddingFusion.2.txt rename to Tests/TokamakStaticHTMLTests/__Snapshots__/HTMLTests/testPaddingFusion.2.html