Compound - Swift 6.2 and Main actor isolation (#5109)

* compound is now using 6.2 and main actor isolation + some tweaks to make it build tests and EX

* better handling of the nonisolated context for CompoundUIColors

* improving docs

* fix comment

* remove unused Sendable conformance
This commit is contained in:
Mauro
2026-02-16 11:19:12 +01:00
committed by GitHub
parent b4eedfef59
commit 26bfa6ed7c
20 changed files with 65 additions and 34 deletions
@@ -11,6 +11,7 @@ import Foundation
import SwiftUI
import XCTest
@MainActor
final class DecorativeColorsTests: XCTestCase {
struct TestCase {
let input: String
@@ -10,6 +10,7 @@
import SwiftUI
import XCTest
@MainActor
final class FontSizeTests: XCTestCase {
/// Test all system text styles to assert mapping between `Font` and `UIFont`.
func testTextStyle() {
@@ -103,3 +104,4 @@ final class FontSizeTests: XCTestCase {
XCTAssertEqual(styledCustomFootnote15FontSize?.style, .footnote)
}
}
@@ -10,20 +10,25 @@
import Foundation
import XCTest
@MainActor
class OverrideColorTests: XCTestCase {
func testSwiftUI() {
let colors = CompoundColors()
let tokens = CompoundColorTokens()
XCTAssertEqual(colors.textPrimary, tokens.textPrimary)
colors.override(\.textPrimary, with: .pink)
XCTAssertEqual(colors.textPrimary, .pink)
colors.override(\.textPrimary, with: nil)
XCTAssertEqual(colors.textPrimary, tokens.textPrimary)
final class OverrideColorTests: XCTestCase {
func testSwiftUI() async {
// For some very weird reason we need this to be async, `@MainActor` is not enough
// it will compile but when running it will crash at the end of the run due to some deinit problems.
// The other solution would be to make CompoundColors nonisolated but we don't really need that.
await MainActor.run {
let colors = CompoundColors()
let tokens = CompoundColorTokens()
XCTAssertEqual(colors.textPrimary, tokens.textPrimary)
colors.override(\.textPrimary, with: .pink)
XCTAssertEqual(colors.textPrimary, .pink)
colors.override(\.textPrimary, with: nil)
XCTAssertEqual(colors.textPrimary, tokens.textPrimary)
}
}
/// UIColors are nonisolated, so this is fine.
func testUIKit() {
let colors = CompoundUIColors()
let tokens = CompoundUIColorTokens()
@@ -8,7 +8,7 @@
import Combine
@testable import Compound
@testable import SnapshotTesting
@preconcurrency @testable import SnapshotTesting
import SwiftUI
import XCTest
@@ -28,15 +28,17 @@ class PreviewTests: XCTestCase {
.init(name: "iPad", device: "iPad")]
private var recordMode: SnapshotTestingConfiguration.Record = .missing
override func setUp() {
super.setUp()
override func setUp() async throws {
try await super.setUp()
if ProcessInfo().environment["RECORD_FAILURES"].map(Bool.init) == true {
recordMode = .failed
}
await MainActor.run {
if ProcessInfo().environment["RECORD_FAILURES"].map(Bool.init) == true {
recordMode = .failed
}
checkEnvironments()
UIView.setAnimationsEnabled(false)
checkEnvironments()
UIView.setAnimationsEnabled(false)
}
}
/// Check environments to avoid problems with snapshots on different devices or OS.
@@ -183,6 +185,7 @@ private extension PreviewDevice {
}
private extension Snapshotting where Value: SwiftUI.View, Format == UIImage {
@MainActor
static func prefireImage(drawHierarchyInKeyWindow: Bool = false,
preferences: SnapshotPreferences,
layout: SwiftUISnapshotLayout = .sizeThatFits,
@@ -204,7 +207,7 @@ private extension Snapshotting where Value: SwiftUI.View, Format == UIImage {
}
return SimplySnapshotting<UIImage>(pathExtension: "png", diffing: .prefireImage(preferences: preferences, scale: traits.displayScale))
.asyncPullback { view in
.asyncPullback { @MainActor view in
var config = config
let controller: UIViewController