Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrandonw committed Sep 14, 2024
1 parent 3d9810e commit 012a4cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
11 changes: 6 additions & 5 deletions Tests/DependenciesTests/BaseTestCaseTests.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Dependencies
import XCTest

#if !arch(wasm32)
final class BaseTestCaseTests: DerivedBaseTestCase {
override func setUp() async throws {
try await super.setUp()
Expand Down Expand Up @@ -30,7 +31,9 @@ final class BaseTestCaseTests: DerivedBaseTestCase {
XCTAssertEqual(DependencyValues._current.uuid(), .deadbeef)
}
}
#endif

#if !arch(wasm32)
class DerivedBaseTestCase: BaseTestCase {
override func setUp() async throws {
try await super.setUp()
Expand All @@ -47,6 +50,7 @@ class DerivedBaseTestCase: BaseTestCase {
}
}
}
#endif

class BaseTestCase: XCTestCase {
override func setUp() async throws {
Expand All @@ -55,18 +59,15 @@ class BaseTestCase: XCTestCase {
XCTAssertEqual(DependencyValues._current.uuid(), .deadbeef)
}

#if !arch(wasm32)
override func invokeTest() {
withDependencies {
// NB: It doesn't seem possible to detect a test context from Wasm:
// https://github.com/swiftwasm/carton/issues/400
#if os(WASI)
$0.context = .test
#endif
$0.uuid = .constant(.deadbeef)
} operation: {
super.invokeTest()
}
}
#endif
}

extension UUID {
Expand Down
12 changes: 7 additions & 5 deletions Tests/DependenciesTests/DependencyValuesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -400,15 +400,15 @@ final class DependencyValuesTests: XCTestCase {

@MainActor
func testEscapingInFeatureModel_InstanceVariablePropagated() async {
let expectation = self.expectation(description: "escape")
let finished = LockIsolated(false)

@MainActor
class FeatureModel /*: ObservableObject*/ {
@Dependency(\.fullDependency) var fullDependency
func doSomething(expectation: XCTestExpectation) {
func doSomething(finished: LockIsolated<Bool>) {
DispatchQueue.main.async {
XCTAssertEqual(self.fullDependency.value, 42)
expectation.fulfill()
finished.withValue { $0 = true }
}
}
}
Expand All @@ -419,8 +419,10 @@ final class DependencyValuesTests: XCTestCase {
FeatureModel()
}

model.doSomething(expectation: expectation)
await fulfillment(of: [expectation], timeout: 1)
model.doSomething(finished: finished)
while !finished.withValue({ $0 }) {
await Task.yield()
}
}

func testEscapingInFeatureModel_NotPropagated() async {
Expand Down

0 comments on commit 012a4cf

Please sign in to comment.