skyweb07 / snap.swift Goto Github PK
View Code? Open in Web Editor NEWSnapshot testing in a snap ๐จ
License: MIT License
Snapshot testing in a snap ๐จ
License: MIT License
When using libraries like SnapKit
or Cartography
the layout constraints won't update, we need to manually call view.layoutIfNeeded()
in order to force layout updates
Hey there!
I've been trying to use this framework and stumbled across this issue.
It appears that Custom Fonts don't load on Unit Tests.
Do you know any workaround this? Or will you think on supporting it somehow?
Thanks ๐๐ป
I find it pretty weird to import something with an underscore in Swift. I'm switching over from FBSnapshotTestcase to Snap.swift mainly because this library is written in Swift (not Objective-C) โ but this line makes me really feel like it's not designed for Swift at all:
import Snap_swift
Couldn't we rename the library to what it should be named, just Snap
? Even the project file is Snap
and seeing Snap.swift
as a file whose name is Snap
also implies the library should be called Snap
.
I would even find SnapDotSwift
or SnapSwift
better then Snap_swift
.
Currently, when I follow the XCTest naming guidelines and write test names like this:
func testBasicRendering() {
expect(snapshotView).toMatchSnapshot()
}
I get files named like this:
I would have expected the name to be reference_basicrendering
, so the test
prefix should be removed as it is part of any test method. It's redundant information.
UIImage+Render currently uses the old UIGraphicsBeginImageContextWithOptions API before iOS 10, and on iOS 10 it starts to use the new UIGraphicsImageRenderer.
Because of this, when you generate test images under iOS 9, the image metadata will differ from the metadata of test images under iOS 10.
My workaround is to only generate the image using the old API...
Make the configuration path a first citizen by allowing to be configured from code
Snap will render an empty, transparent image for SKViews. As a workaround, checking and handling for Spritekit in UIView+Render
seems to do the trick:
if let skview = self as? SKView {
return UIImage(cgImage: skview.texture(from: skview.scene!)!.cgImage())
}
When writing layout code, you should rely on the view/viewController's traitCollection instead of just the frame of the view.
However, when executing the snapshot tests for a device, the traitCollection during the test execution is the same as the current simulator, which is not ideal when using expect(view).toMatchSnapshot(for: .allDevices)
since an invalid collection is passed here.
We should either notify this in the documentation or (preferably) override the traitCollection of the UIView using override trait collection
Add Xcode template for snapshot testing
Hi, thanks so much for this library!
I recently migrate from FBSnapshotTestCase and I was wondering if it would be possible to integrate Kaleidoscope?
It was very useful in FBSnapshotTestCase when it fail to compare easily with Kaleidoscope with the
ksdiff command line directly in the console.
Thanks !
This tool is no longer required as the unc0ver team have allowed sileo to work
Originally posted by @demhademha in demhademha/sileo-apt-#1
Make the lib to be able to take screenshot from view controller with multiple sizes
something like example
expect(viewController).toMatchSnapshot(for devices: [.iphone4, .iphone5s])
expect(viewController).toMatchSnapshot(for: .allDevices)
last release was 6 months ago..
It would be nice if there would be support for setting the view to landscape orientation.
Maybe just treating them as a separate Device? Like:
extension Device {
public var size: CGSize {
switch self {
// ...
case .iPadAir: return CGSize(width: 768, height: 1024)
case .iPadAir_Landscape: return CGSize(width: 1024, height: 768)
// ...
}
}
I have a consistent failure for GitHawkApp/StyledTextKit#44 only on Travis CI that I'm struggling to debug. Everything is green locally, but just a single test repeatedly fails on Travis.
If I run the same xcodebuild
command locally, everything passes. Same goes for testing within Xcode.
Any tips?
I'm new to snapshot testing, are there are recommending/guidelines to follow when testing?
I have this strange behaviour when I create images for iPhone x it passes and when I try to use another simulator it fails. from the diffs, I can see that the UI is slightly higher by about 4/5 px.
Is there a reason for setting the width to 788 or is this a typo?
Also, does it need a special device for the iPad mini which has the same resolution as the iPad Air?
Something like
expect(view).toMatchSnapshot("name")
Or at least output the offending test image somewhere.
When generating the snapshots, the alpha channels around the border of the items seem to have some weird opaque colors, I think this has to be with this line
, we may need to remove it to get the image without those weird bordersExample:
Hi there and thanks for this library. I just wanted to try this out using Carthage but I noticed immediately that when adding this library via Carthage it installs two dependencies. I couldn't find those dependencies defined in the podspec though and the only usage I find in the project is here during testing.
Currently you are specifying those dependencies as framework dependencies. What you really want if you only need them for testing is to specify them as development dependencies. You can do this by using a file named Cartfile.private
instead of Cartfile
. Actually don't need a Cartfile
to support Carthage if you don't have any dependencies you're relying on. It's enough to have a shared schema to support Carthage.
This line returns nil
when the project path has a space in it. I tried hacking around this, but am getting blocked at the moment. I'm going to update my project paths for the time being, but wanted to flag that this took me a minute to debug.
In one of my tests I need to see what a view would look like on different devices, but the view is going to be part of a scrollview and therefore is potentially longer than the screen is long. I'd like to test that my view looks correct for each width of a device, but there's no way currently to do that.
The easiest way to allow this is to make the Device sizes public.
Allow passing a custom error threshold
Currently, when I follow the Swift guidelines and write test names like this:
func testBasicRendering() {
expect(snapshotView).toMatchSnapshot()
}
I get files named like this:
I would have expected the name to be reference_testBasicRendering
or at least reference_test_basic_rendering
, but Snap doesn't seem to recognize camelCased method names which are the Swift default convention. This should be definitely added IMHO.
It would be awesome if there would be an API to compare an UIImage to be able to visually inspect images, for example to test rendering code without creating full views.
Something like: expect(image: UIImage)
Current workaround: expect(UIImageView(image: image))
In case "Reference image not found" happens, it would be awesome if Snap.swift would write the Failed image.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.