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 <max@desiatov.com>
This commit is contained in:
parent
19bcf2746b
commit
88cee68bee
|
@ -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
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue