Skip to content

Swift 6 warnings and snapshotting WKWebView on macOS #984

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

Open
hanneskaeufler opened this issue May 6, 2025 · 1 comment
Open

Swift 6 warnings and snapshotting WKWebView on macOS #984

hanneskaeufler opened this issue May 6, 2025 · 1 comment

Comments

@hanneskaeufler
Copy link

Describe the bug
It appears we're currently stuck between a rock and a hard place when snapshotting a WKWebView on macOS.
When using Swift-Testing, in swift 5 mode, we get the concurrency warnings, but the snapshotting appears to work.
When switching to swift 6 mode and annotating the test @MainActor, the snapshotting hangs.

To Reproduce

Create a Unit Test Bundle and add swift-snapshot-testing to the dependencies of the project. Use Swift-Testing as the test framework. Create the following swift test. Use swift 5 mode.

import Testing
import WebKit
import SnapshotTesting

struct MySnaphotTests {

    @Test func example() async throws {
        let webView = WKWebView() // Expression is 'async' but is not marked with 'await'; this is an error in the Swift 6 language mode
        webView.loadHTMLString("<html><body><h1>Hello, World!</h1></body></html>", baseURL: nil) // Expression is 'async' but is not marked with 'await'; this is an error in the Swift 6 language mode

        assertSnapshot(
            of: webView, as: .image(size: .init(width: 800, height: 600)),
            timeout: 10)
    }
}

Expected behavior
No concurrency warnings. Or adding @MainActor to the test and not having it hang/timeout.

Screenshots

Warnings without @MainActor
Image

Crash with @MainActor
Image
If applicable, add screenshots to help explain your problem.

Environment

  • swift-snapshot-testing version 1.18.3
  • Xcode 116.3
  • Swift 5
  • OS: macOS 15.2
@hanneskaeufler
Copy link
Author

I presume this is different than #805 and also #888 didn't solve it for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant