-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Added ScreenshotTestHelpers #2682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
c9a774b
5572459
b0b1e66
28b5e97
2520d22
0183559
2a29112
3bd34f1
7cf3b08
aa5b2ee
70e5df3
b83c70f
c985900
ce6999f
f634f62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I still find these file names to be way too long to be practical, at least in my personal work flow. Maybe it's worth checking with the team what info they find necessary in a snapshot test? Personally, I don't think things like device type and size category are useful enough to be worth the extra words, but I'm okay with being outvoted. Even without removing information, there's still some things you could do to make the name more streamlined. The full path of this one is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can drop the file/test prefix from the named: value so the filename is just the config (device/lang/style/font/orientation), and let the test’s Snapshots/testLoginToutView/ folder provide the test context. I’ll also shorten the content-size labels—thinking a11yXXXL as a common shorthand for “accessibility” to keep names shorter, but I can spell out “accessibilityXXXL” if you prefer. With these tweaks, a filename would look like phone4_7inch_en_dark_a11yXXXL_portrait.png. If the team wants to trim further (e.g., drop style/font), I can do that too. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,4 +98,5 @@ internal func orthogonalCombos<A, B, C, D, E>( | |
| ) | ||
| } | ||
| } | ||
|
|
||
| // swiftlint:enable large_tuple | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,10 +113,10 @@ internal func assertSnapshot( | |
| forController controller: UIViewController, | ||
jlpl15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| withType type: ScreenshotType, | ||
| perceptualPrecision: Float? = nil, | ||
| record _: Bool = false, | ||
| record: Bool = false, | ||
| file: StaticString = #file, | ||
| testName: String = #function, | ||
| line _: UInt = #line | ||
| line: UInt = #line | ||
| ) { | ||
| let contentSizeTraits = UITraitCollection( | ||
| preferredContentSizeCategory: type.contentSizeCategory | ||
|
|
@@ -149,19 +149,26 @@ internal func assertSnapshot( | |
| return .image | ||
| }() | ||
|
|
||
| let directory = snapshotDirectory(for: file) | ||
|
|
||
| if let failure = verifySnapshot( | ||
| of: parent.view, | ||
| as: strategy, | ||
| named: name, | ||
| record: record, | ||
| snapshotDirectory: directory, | ||
| file: file, | ||
| testName: testName, | ||
| line: line | ||
| ) { | ||
| XCTFail( | ||
| """ | ||
| Snapshot failed for \(name) | ||
| device=\(type.device.snapshotDescription), lang=\(type.language.rawValue), style=\(type.style.snapshotDescription), font=\(type.contentSizeCategory.rawValue), orientation=\(type.orientation.snapshotDescription) | ||
| device=\(type.device.snapshotDescription), | ||
| lang=\(type.language.rawValue), | ||
| style=\(type.style.snapshotDescription), | ||
| font=\(type.contentSizeCategory.rawValue), | ||
| orientation=\(type.orientation.snapshotDescription) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great, thanks for adding! |
||
| \(failure) | ||
| """, | ||
| file: file, | ||
|
|
@@ -178,7 +185,7 @@ internal func assertSnapshot( | |
| size: CGSize? = nil, | ||
| useIntrinsicSize: Bool = false, | ||
| perceptualPrecision: Float? = nil, | ||
| record _: Bool = false, | ||
| record: Bool = false, | ||
| file: StaticString = #file, | ||
| testName: String = #function, | ||
| line: UInt = #line | ||
|
|
@@ -242,19 +249,26 @@ internal func assertSnapshot( | |
| return .image | ||
| }() | ||
|
|
||
| let directory = snapshotDirectory(for: file) | ||
|
|
||
| if let failure = verifySnapshot( | ||
| of: parent.view, | ||
| as: strategy, | ||
| named: name, | ||
| record: record, | ||
| snapshotDirectory: directory, | ||
| file: file, | ||
| testName: testName, | ||
| line: line | ||
| ) { | ||
| XCTFail( | ||
| """ | ||
| Snapshot failed for \(name) | ||
| device=\(type.device.snapshotDescription), lang=\(type.language.rawValue), style=\(type.style.snapshotDescription), font=\(type.contentSizeCategory.rawValue), orientation=\(type.orientation.snapshotDescription) | ||
| device=\(type.device.snapshotDescription), | ||
| lang=\(type.language.rawValue), | ||
| style=\(type.style.snapshotDescription), | ||
| font=\(type.contentSizeCategory.rawValue), | ||
| orientation=\(type.orientation.snapshotDescription) | ||
| \(failure) | ||
| """, | ||
| file: file, | ||
|
|
@@ -271,7 +285,7 @@ internal func assertSnapshot<Content: View>( | |
| size: CGSize? = nil, | ||
| useIntrinsicSize: Bool = false, | ||
| perceptualPrecision: Float? = nil, | ||
| record _: Bool = false, | ||
| record: Bool = false, | ||
| file: StaticString = #file, | ||
| testName: String = #function, | ||
| line: UInt = #line | ||
|
|
@@ -366,11 +380,23 @@ private extension Orientation { | |
| } | ||
| } | ||
|
|
||
| // MARK: - Private helpers | ||
| private extension UIUserInterfaceStyle { | ||
| var snapshotDescription: String { | ||
| switch self { | ||
| case .light: return "light" | ||
| case .dark: return "dark" | ||
| default: return "unspecified" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private func snapshotDirectory(for file: StaticString) -> String { | ||
| let fileURL = URL(fileURLWithPath: "\(file)") | ||
| return fileURL.deletingLastPathComponent().appendingPathComponent("__Snapshots__").path | ||
| } | ||
|
|
||
| private func withLanguage(_ language: Language, body: () -> Void) { | ||
| AppEnvironment.pushEnvironment(language: language) | ||
| body() | ||
| AppEnvironment.popEnvironment() | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.