From c726c8b15e8cf29824d6f283a59e2c7bc3fcaa1c Mon Sep 17 00:00:00 2001 From: Noah Martin Date: Tue, 30 Apr 2024 17:34:26 -0700 Subject: [PATCH] Basic support for catalyst tests (#111) --- DemoApp/DemoApp.xcodeproj/project.pbxproj | 4 ++-- DemoApp/DemoApp/DemoApp.entitlements | 7 +------ Package.swift | 2 +- Sources/SnapshottingSwift/Snapshots.swift | 4 ++-- Sources/SnapshottingTests/PreviewTest.m | 4 ++-- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/DemoApp/DemoApp.xcodeproj/project.pbxproj b/DemoApp/DemoApp.xcodeproj/project.pbxproj index 690ca5d..43f737a 100644 --- a/DemoApp/DemoApp.xcodeproj/project.pbxproj +++ b/DemoApp/DemoApp.xcodeproj/project.pbxproj @@ -611,7 +611,7 @@ CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"DemoApp/Preview Content\""; DEVELOPMENT_TEAM = 62J2XHNK9T; - ENABLE_HARDENED_RUNTIME = YES; + ENABLE_HARDENED_RUNTIME = NO; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; @@ -652,7 +652,7 @@ CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"DemoApp/Preview Content\""; DEVELOPMENT_TEAM = 62J2XHNK9T; - ENABLE_HARDENED_RUNTIME = YES; + ENABLE_HARDENED_RUNTIME = NO; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; "INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES; diff --git a/DemoApp/DemoApp/DemoApp.entitlements b/DemoApp/DemoApp/DemoApp.entitlements index f2ef3ae..0c67376 100644 --- a/DemoApp/DemoApp/DemoApp.entitlements +++ b/DemoApp/DemoApp/DemoApp.entitlements @@ -1,10 +1,5 @@ - - com.apple.security.app-sandbox - - com.apple.security.files.user-selected.read-only - - + diff --git a/Package.swift b/Package.swift index 52913de..15ace00 100644 --- a/Package.swift +++ b/Package.swift @@ -42,7 +42,7 @@ let package = Package( // Target that provides the XCTest .target(name: "SnapshottingTests"), // Core functionality - .target(name: "SnapshotPreviewsCore", dependencies: ["PreviewsSupport", .product(name: "AccessibilitySnapshotCore", package: "AccessibilitySnapshot", condition: .when(platforms: [.iOS]))]), + .target(name: "SnapshotPreviewsCore", dependencies: ["PreviewsSupport", .product(name: "AccessibilitySnapshotCore", package: "AccessibilitySnapshot", condition: .when(platforms: [.iOS, .macCatalyst]))]), .target(name: "SnapshotPreferences", dependencies: ["SnapshotPreviewsCore"]), // Inserted dylib .target(name: "Snapshotting", dependencies: ["SnapshottingSwift"]), diff --git a/Sources/SnapshottingSwift/Snapshots.swift b/Sources/SnapshottingSwift/Snapshots.swift index ca02285..3ac73f3 100644 --- a/Sources/SnapshottingSwift/Snapshots.swift +++ b/Sources/SnapshottingSwift/Snapshots.swift @@ -25,7 +25,7 @@ extension SnapshotError: LocalizedError { } class Snapshots { - let server = HTTPServer(port: 8080) + let server = HTTPServer(port: 38824) let testHandler: NSObject.Type? = NSClassFromString("EMGTestHandler") as? NSObject.Type public init() { @@ -34,7 +34,7 @@ class Snapshots { .filter { $0.activationState == .foregroundActive } .first - let window = UIWindow(windowScene: windowScene as! UIWindowScene) + let window = windowScene != nil ? UIWindow(windowScene: windowScene as! UIWindowScene) : UIWindow() window.windowLevel = .statusBar + 1 window.backgroundColor = UIColor.systemBackground window.makeKeyAndVisible() diff --git a/Sources/SnapshottingTests/PreviewTest.m b/Sources/SnapshottingTests/PreviewTest.m index ae7d642..137f20e 100644 --- a/Sources/SnapshottingTests/PreviewTest.m +++ b/Sources/SnapshottingTests/PreviewTest.m @@ -97,7 +97,7 @@ - (void)generateSnapshots { [app launch]; XCTestExpectation *expectation = [self expectationWithDescription:@"Waiting for network response"]; - NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8080/file"]]; + NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:38824/file"]]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { if (data) { @@ -164,7 +164,7 @@ void dynamicTestMethod(id self, SEL _cmd) { NSString *typeName = typeNames[index]; NSNumber *previewId = previewIds[index]; XCTestExpectation *expectation = [self expectationWithDescription:@"Waiting for network response"]; - NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:8080/display/%@/%d", typeName, previewId.intValue]]; + NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:38824/display/%@/%d", typeName, previewId.intValue]]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; __block NSData *resultData;