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
Fix crash when using UIWindow
in assertSnapshot
#366
base: main
Are you sure you want to change the base?
Fix crash when using UIWindow
in assertSnapshot
#366
Conversation
`prepareView` in `View.swift` will now check if the current snapshot target is a `UIWindow`. If that condition is `true`, then it will return early and use the window as its dispose value. It will make the assumption that the window has a `rootViewController` set and use that as it's `viewController`. This avoids unbalanced calls to appearance transitions during test teardown which will throw exceptions and crash the test.
the second time around.
Rely on configuration options instead.
39c79e2
to
e04b8e1
Compare
@stephencelis mind taking a look a this? 😎 |
Hey @zenangst! Thanks for taking the time to submit this and sorry if things are taking a bit longer to take a look at. Given the early out does this mean that the traits and sizing will not be applied to the window? |
Yeah traits and sizing should be left out. Maybe that is a false assumption on my part but if you give it the window then everything down the line should already be handled in your test. What do you think? |
@stephencelis I pushed another commit to include the traits if the root view controller of the window could be resolved. |
if let rootViewController = window.rootViewController { | ||
return add(traits: traits, viewController: rootViewController, to: window) | ||
} else { | ||
return {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add an assertFailure
here
ping @stephencelis 😎 |
Any headway here? Something that needs changing before it can be merged? 🌞 |
This way, we don't accidentally hit bad transition points in tests, as per pointfreeco#366. Basically, because we're necessarily running our tests inside of a hosted application, the snapshot library incorrectly creates yet another window in which to run tests, which confuses the ... iOS runtime? or something and causes the app to queue up a bunch of appear / disappear transitions that clog up the main thread until they just halt the entire app, causing the app to stop for a solid 20-30 seconds, which explains timeout issues we're having in CI and occasionally locally. The cost of this is that the `onAppear` triggers no longer trigger in snapshot tests, but that's a small price to pay to make sure the tests actually pass in CI.
This way, we don't accidentally hit bad transition points in tests, as per pointfreeco#366. Basically, because we're necessarily running our tests inside of a hosted application, the snapshot library incorrectly creates yet another window in which to run tests, which confuses the ... iOS runtime? or something and causes the app to queue up a bunch of appear / disappear transitions that clog up the main thread until they just halt the entire app, causing the app to stop for a solid 20-30 seconds, which explains timeout issues we're having in CI and occasionally locally. The cost of this is that the `onAppear` triggers no longer trigger in snapshot tests, but that's a small price to pay to make sure the tests actually pass in CI.
This way, we don't accidentally hit bad transition points in tests, as per pointfreeco#366. Basically, because we're necessarily running our tests inside of a hosted application, the snapshot library incorrectly creates yet another window in which to run tests, which confuses the ... iOS runtime? or something and causes the app to queue up a bunch of appear / disappear transitions that clog up the main thread until they just halt the entire app, causing the app to stop for a solid 20-30 seconds, which explains timeout issues we're having in CI and occasionally locally. The cost of this is that the `onAppear` triggers no longer trigger in snapshot tests, but that's a small price to pay to make sure the tests actually pass in CI.
This way, we don't accidentally hit bad transition points in tests, as per pointfreeco#366. Basically, because we're necessarily running our tests inside of a hosted application, the snapshot library incorrectly creates yet another window in which to run tests, which confuses the ... iOS runtime? or something and causes the app to queue up a bunch of appear / disappear transitions that clog up the main thread until they just halt the entire app, causing the app to stop for a solid 20-30 seconds, which explains timeout issues we're having in CI and occasionally locally. The cost of this is that the `onAppear` triggers no longer trigger in snapshot tests, but that's a small price to pay to make sure the tests actually pass in CI.
Please merge, I also encounter this issue |
I merged this with |
@stephencelis will you merge this one, we are also having the same issue and it has been more then one year since @zenangst requested this PR? That would be great if you merge, we don't want to continue with forked one, thanks :) |
We have those changes on our fork for a while now and it works perfectly. Maybe this could be somehow merged? 🐱🙏 |
prepareView
inView.swift
will now check if the current snapshottarget is a
UIWindow
. If that condition istrue
, then it will returnearly and use the window as its dispose value. It will make the assumption
that the window has a
rootViewController
set and use that as it'sviewController
.This avoids unbalanced calls to appearance transitions during test teardown
which will throw exceptions and crash the test.