Skip to content

Commit e7d2849

Browse files
authored
Add docs for SWIFT_DEPENDENCIES_CONTEXT. (#115)
* Add docs for SWIFT_DEPENDENCIES_CONTEXT. * wip * wip
1 parent 720e68a commit e7d2849

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Sources/Dependencies/Documentation.docc/Articles/LivePreviewTest.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,22 @@ On the flip side, the library also helps you catch when you have not provided a
284284
running the application in the simulator or on a device, if a dependency is accessed for which a
285285
`liveValue` has not been provided, a purple, runtime warning will appear in Xcode letting you know.
286286

287+
There is also a way to force a dependency context in an application target or test target. When
288+
the environment variable `SWIFT_DEPENDENCIES_CONTEXT` is present, and is equal to either `live`,
289+
`preview` or `test`, that context will be used. This can be useful in UI tests since the application
290+
target runs as a separate process outside of the testing process.
291+
292+
In order to force the application target to run with test dependencies during a UI test, simply
293+
perform the following in your UI test case:
294+
295+
```swift
296+
func testFeature() {
297+
self.app.launchEnvironment["SWIFT_DEPENDENCIES_CONTEXT"] = "test"
298+
self.app.launch()
299+
300+
}
301+
```
302+
287303
[unimplemented-docs]: https://pointfreeco.github.io/xctest-dynamic-overlay/main/documentation/xctestdynamicoverlay/unimplemented(_:fileid:line:)-5098a
288304
[xctest-dynamic-overlay-gh]: http://github.com/pointfreeco/xctest-dynamic-overlay
289305

Tests/DependenciesTests/DependencyValuesTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,11 @@ final class DependencyValuesTests: XCTestCase {
622622
#endif
623623

624624
func testThreadSafety() async {
625+
#if os(Windows)
626+
let runCount = 1_000
627+
#else
625628
let runCount = 100_000
629+
#endif
626630
let taskCount = 10
627631

628632
for _ in 1...runCount {

0 commit comments

Comments
 (0)