pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.
https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing
MIT License
3.74k stars 570 forks source link

Unbalanced calls to begin/end transition #700

Open maciej-siciarz-ccc opened 1 year ago

maciej-siciarz-ccc commented 1 year ago

Describe the bug Running snapshot generates Unbalanced calls to begin/end transition for view controller message. View controller in question is the one created here

To Reproduce Launch UnbalancedCallsTests

UnbalancedCalls.zip

Expected behaviour Calls to begin/end transition are balanced.

Environment

Additional context Why is this an issue? In our project we have almost 400 snapshots. When running them all message is not printed to console immediately, but it seems they are left unprocessed by runloop until in one test when waiting for snapshot all (or most?) of them are processed at once causing timeout in that test (when run on our CI, but sometimes it did happen also on local machine). Yes, we can increase timeout for that test, but it's just workaround and won't change fact that after adding additional snapshots this issue will cause other test to fail.

From my investigation it looks like additional beginAppearanceTransition is called by UIWindow.rootViewController setter (not directly), used in add private method in View.swift which creates unbalanced view controller. I tried removing manual calls to beginAppearanceTransition seen in add method, but then additional beginAppearanceTransition call occurred as effect of layoutIfNeeded.

Some stackoverflow answers suggest this message is generated when view controller is beginning it's appearance transition before appearance of its parent has ended.

Issue #538 seems to be related (or even the same).