swift-snapshot-testing
swift-snapshot-testing copied to clipboard
Added `name` property to ViewImageConfig (#223)
Once the device structs are created (e.g. .iPhone8
), there is no good way to get a short description of what they are (iPhone8_Portrait
) by using an extension since so much of what makes it unique is part of the initializer.
This .name
property gives a descriptive short name which is useful when creating snapshot file names or log statements, for instance:
[.iPhone8, .iPadMini].forEach { device in
print("Device name: \(device.name)")
}
// "Device name: iPhone8_Portrait"
// "Device name: iPadMini_Landscape"
Two notes:
- I added the
name
parameter at the end of the list ofinit
parameters because it read better when initializing with a name to have the traits and the name next to each other. I wasn't sure if you wanted the parameters to be in alphabetical order or if it was just happenstance. Compare:
return .init(safeArea: safeArea, size: size, traits: .iPhoneSe(orientation), name: "iPhoneSe_\(orientation.name)")
and
return .init(name: "iPhoneSe_\(orientation.name)", safeArea: safeArea, size: size, traits: .iPhoneSe(orientation))
- I did not make this a
CustomDebugStringConvertible
as suggested in #223 because it would be a breaking change and I did not feel like it was right for me to submit a breaking change for a small feature. Other people might depend on the verbose output of.debugDescription
for their tests.
If you want me to update my PR for any reason I'm obviously open to that.
Thanks for making this available.
This is a very nice change to have in the project. Do we have plan to merge it? Maybe you need help to resolve conflict in case we get okey to merge it?
I have rebased the PR, but I've been waiting a year for this to be reviewed. If you don't want this change let me know and I will close the PR, but ignoring it seems like the worst possible option.
I understand if you don't want this change in your code, but just tell me.
My colleagues and I have been using this change to great effect for the last three years.
Thank you.