diff --git a/Tests/SnapshotTestingTests/SnapshotTestingTests.swift b/Tests/SnapshotTestingTests/SnapshotTestingTests.swift index 4a5df06c0..4a42d7b9f 100644 --- a/Tests/SnapshotTestingTests/SnapshotTestingTests.swift +++ b/Tests/SnapshotTestingTests/SnapshotTestingTests.swift @@ -1133,6 +1133,18 @@ final class SnapshotTestingTests: XCTestCase { let firstLine = message?.split(whereSeparator: \.isNewline).first XCTAssertEqual(firstLine, "[\(platform)] Snapshot size (123.0, 123.0) is unequal to expected size (100.0, 100.0)") } + + func testSnapshotUnscaledByDefault() throws { + let size = CGSize(width: 100, height: 100) + let view = TestView(size: size) + view.backgroundColor = .cyan + assertSnapshot(of: view, as: .image) + let url = URL(fileURLWithPath: String(#file), isDirectory: false) + .deletingLastPathComponent() + .appendingPathComponent("__Snapshots__/SnapshotTestingTests/testSnapshotUnscaledByDefault.1.png") + let image = try XCTUnwrap(XImage(contentsOf: url)) + XCTAssertEqual(image.size, size) + } #endif #if os(iOS) diff --git a/Tests/SnapshotTestingTests/TestHelpers.swift b/Tests/SnapshotTestingTests/TestHelpers.swift index f708c40eb..3ee99ff41 100644 --- a/Tests/SnapshotTestingTests/TestHelpers.swift +++ b/Tests/SnapshotTestingTests/TestHelpers.swift @@ -110,3 +110,34 @@ let osVersion = ProcessInfo.processInfo.operatingSystemVersion } } #endif + +#if os(iOS) || os(macOS) || os(tvOS) + extension XImage { + convenience init?(contentsOf url: URL) { + #if os(iOS) || os(tvOS) + self.init(contentsOfFile: url.path) + #elseif os(macOS) + self.init(byReferencing: url) + #endif + } + } +#endif + +class TestView: XView { + #if os(macOS) + var backgroundColor: NSColor? { + get { + guard let cgColor = layer?.backgroundColor else { return nil } + return NSColor(cgColor: cgColor) + } + set { + wantsLayer = true + layer?.backgroundColor = newValue?.cgColor + } + } + #endif + + convenience init(size: CGSize) { + self.init(frame: .init(origin: .zero, size: size)) + } +} diff --git a/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testSnapshotUnscaledByDefault.1.png b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testSnapshotUnscaledByDefault.1.png new file mode 100644 index 000000000..af261e5fb Binary files /dev/null and b/Tests/SnapshotTestingTests/__Snapshots__/SnapshotTestingTests/testSnapshotUnscaledByDefault.1.png differ