Skip to content

Swift 6 warnings and snapshotting WKWebView on macOS #984

Open
@hanneskaeufler

Description

@hanneskaeufler

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions