You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The crash occurs because ViewInspector's precondition is not safeguarded against external manipulation during testing. Once the static window is initialized and set as the keyWindow, it becomes accessible to other tests, leading to potential crashes.
The following example demonstrates how to reproduce the crash (tested in Xcode 15.4, Simulator iOS 17.5):
import SwiftUI
import ViewInspector
import XCTest
finalclassViewInspectorCrash:XCTestCase{func testViewInspectorCrash(){letview=Text("Crash")
// This triggers the one-time creation of ViewHosting.window
ViewHosting.host(view: view)
// The created window is now the keyWindow and can be accessed and manipulated by any other test
UIApplication.shared.keyWindow?.rootViewController =nil
// Manipulation from another test will lead to a crash:
ViewHosting.host(view: view)}}
Each test execution should be isolated and safe from external interference (ensuring the static window/window.rootViewController is reset or properly cleaned or implementing checks to verify the integrity of the keyWindow before it is used).
The text was updated successfully, but these errors were encountered:
Description of the Issue
The crash occurs because ViewInspector's precondition is not safeguarded against external manipulation during testing. Once the
static window
is initialized and set as thekeyWindow
, it becomes accessible to other tests, leading to potential crashes.ViewInspector/Sources/ViewInspector/ViewHosting.swift
Lines 136 to 145 in 21a2ff9
The crash itself will be triggered here:
ViewInspector/Sources/ViewInspector/ViewHosting.swift
Lines 161 to 163 in 21a2ff9
Steps to Reproduce
The following example demonstrates how to reproduce the crash (tested in Xcode 15.4, Simulator iOS 17.5):
Each test execution should be isolated and safe from external interference (ensuring the
static window
/window.rootViewController
is reset or properly cleaned or implementing checks to verify the integrity of thekeyWindow
before it is used).The text was updated successfully, but these errors were encountered: