swift-snapshot-testing icon indicating copy to clipboard operation
swift-snapshot-testing copied to clipboard

Run runActivity on main thread (#895)

Open sk409 opened this issue 1 year ago • 2 comments

Fixes #895 .

sk409 avatar Aug 27 '24 08:08 sk409

Hi @sk409, I believe the only way runActivity could be called on a background thread is if your test is running on a background thread. Instead of this change can you mark your test with @MainActor?

We have plans to more deeply integrate snapshot testing with Swift's concurrency tools, but until then you will need to be responsible for calling its APIs on the main thread.

mbrandonw avatar Aug 29 '24 17:08 mbrandonw

@mbrandonw My app uses SDWebImageSwiftUI to display images. SDWebImageSwiftUI updates views on the main thread, so when I run the test on the main thread, XCTWaiter.wait blocks updating views. Therefore, the image will no longer be displayed in the snapshot. For the reasons mentioned above I need to run my tests on a background thread instead of the main thread.

※SDWebImageSwiftUI performs the following processing on the main thread.

  • https://github.com/SDWebImage/SDWebImageSwiftUI/blob/master/SDWebImageSwiftUI/Classes/ImageManager.swift#L99
  • https://github.com/SDWebImage/SDWebImageSwiftUI/blob/master/SDWebImageSwiftUI/Classes/ImageManager.swift#L20

sk409 avatar Aug 30 '24 01:08 sk409