pointfreeco / swift-snapshot-testing

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

SwiftUI `Menu` regression with iOS 15.4 #598

Open jpsim opened 2 years ago

jpsim commented 2 years ago

Describe the bug

There was a regression in iOS 15.4 that causes SwiftUI Menu views to not be rendered in image snapshots. I'm not sure if this is due to a bug in SwiftUI, a bug in this library, or just something this library needs to be updated to handle.

To Reproduce

Run tests with this project in an iOS 15.2 Simulator (e.g. Xcode 13.2.1) and again with an iOS 15.4 Simulator (e.g. Xcode 13.3)

snapshot-testing-menu-issue.zip

This is all that's needed to see the issue:

let view = Menu(content: {}, label: { Text("My Menu") })
assertSnapshot(matching: view, as: .image(layout: .device(config: .iPhone8)))

Expected behavior

The snapshot should display the menu with iOS 15.4 as it did with iOS 15.2 and prior versions.

Screenshots

iOS 15.2 iOS 15.4
before after

Environment

Additional context

Found while updating CI to use Xcode 13.3 when testing my app Zen Tuner: https://github.com/jpsim/ZenTuner/pull/44

Menus render fine in the iOS Simulator, on iOS devices and in Xcode Previews. While the snapshot tests are running, I see the menu rendered correctly in the host app.

gonzalonunez commented 2 years ago

I am seeing the same behavior more generally across all SwiftUI snapshots in my app. We have tons of embedded UIHostingControllers that are giving us blank screenshots on 15.4 (will soon confirm that 15.0 works fine, but this is new behavior for us and that thesis seems likely).

func test_uiHostingController() {  
  let controller = UIHostingController(rootView: VStack {
    Text("Hello, world")
      .foregroundColor(Color.white)
      .padding()
      .background(Color.green)
  })

  assertSnapshot(matching: controller, as: .image)
}

hosting_controller

If we use a SwiftUI.View on its own, only the background color is rendered:

func test_view() {  
  let view = VStack {
    Text("Hello, world")
      .foregroundColor(Color.white)
      .padding()
      .background(Color.green)
  }

  assertSnapshot(matching: view, as: .image)
}

view_background

gonzalonunez commented 2 years ago

Confirmed – snapshots are as-expected on iOS 15.

loloop commented 2 years ago

Just checked on today's release of iOS 15.5/Xcode 13.4 and we're still getting blank snapshots :/

loloop commented 1 year ago

This is @gonzalonunez test_uiHostingController on Xcode 14, iOS 16.0

image

And this is test_view, same setup:

image

@jpsim's Menu code renders fine:

image
gonzalonunez commented 1 year ago

@loloop so now the only thing broken is "raw" SwiftUI views?