Skip to content

Commit

Permalink
Add docs for SWIFT_DEPENDENCIES_CONTEXT. (#115)
Browse files Browse the repository at this point in the history
* Add docs for SWIFT_DEPENDENCIES_CONTEXT.

* wip

* wip
  • Loading branch information
mbrandonw authored Sep 11, 2023
1 parent 720e68a commit e7d2849
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,22 @@ On the flip side, the library also helps you catch when you have not provided a
running the application in the simulator or on a device, if a dependency is accessed for which a
`liveValue` has not been provided, a purple, runtime warning will appear in Xcode letting you know.

There is also a way to force a dependency context in an application target or test target. When
the environment variable `SWIFT_DEPENDENCIES_CONTEXT` is present, and is equal to either `live`,
`preview` or `test`, that context will be used. This can be useful in UI tests since the application
target runs as a separate process outside of the testing process.

In order to force the application target to run with test dependencies during a UI test, simply
perform the following in your UI test case:

```swift
func testFeature() {
self.app.launchEnvironment["SWIFT_DEPENDENCIES_CONTEXT"] = "test"
self.app.launch()
}
```

[unimplemented-docs]: https://pointfreeco.github.io/xctest-dynamic-overlay/main/documentation/xctestdynamicoverlay/unimplemented(_:fileid:line:)-5098a
[xctest-dynamic-overlay-gh]: http://github.com/pointfreeco/xctest-dynamic-overlay

4 changes: 4 additions & 0 deletions Tests/DependenciesTests/DependencyValuesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,11 @@ final class DependencyValuesTests: XCTestCase {
#endif

func testThreadSafety() async {
#if os(Windows)
let runCount = 1_000
#else
let runCount = 100_000
#endif
let taskCount = 10

for _ in 1...runCount {
Expand Down

0 comments on commit e7d2849

Please sign in to comment.