Skip to content

Commit 6fea6e5

Browse files
committedSep 30, 2022
Add short document about JavaScriptEventLoopTestSupport
1 parent f72b207 commit 6fea6e5

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed
 

‎README.md

+17
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ asyncButtonElement.onclick = .object(JSClosure { _ in
125125
_ = document.body.appendChild(asyncButtonElement)
126126
```
127127

128+
### `JavaScriptEventLoop` activation in XCTest suites
129+
130+
If you need to execute Swift async functions that can be resumed by JS event loop in your XCTest suites, please add `JavaScriptEventLoopTestSupport` to your test target dependencies.
131+
132+
```diff
133+
.testTarget(
134+
name: "MyAppTests",
135+
dependencies: [
136+
"MyApp",
137+
+ "JavaScriptEventLoopTestSupport",
138+
]
139+
)
140+
```
141+
142+
Linking this module automatically activates JS event loop based global executor by calling `JavaScriptEventLoop.installGlobalExecutor()`
143+
144+
128145
## Requirements
129146

130147
### For developers

‎Sources/JavaScriptEventLoopTestSupport/JavaScriptEventLoopTestSupport.swift

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
1-
// This module just expose 'JavaScriptEventLoop.installGlobalExecutor' to C ABI
2-
// See _CJavaScriptEventLoopTestSupport.c for why this is needed
1+
/// If you need to execute Swift async functions that can be resumed by JS
2+
/// event loop in your XCTest suites, please add `JavaScriptEventLoopTestSupport`
3+
/// to your test target dependencies.
4+
///
5+
/// ```diff
6+
/// .testTarget(
7+
/// name: "MyAppTests",
8+
/// dependencies: [
9+
/// "MyApp",
10+
/// + "JavaScriptEventLoopTestSupport",
11+
/// ]
12+
/// )
13+
/// ```
14+
///
15+
/// Linking this module automatically activates JS event loop based global
16+
/// executor by calling `JavaScriptEventLoop.installGlobalExecutor()`
317

418
import JavaScriptEventLoop
519

20+
// This module just expose 'JavaScriptEventLoop.installGlobalExecutor' to C ABI
21+
// See _CJavaScriptEventLoopTestSupport.c for why this is needed
622
@_cdecl("swift_javascriptkit_activate_js_executor_impl")
723
func swift_javascriptkit_activate_js_executor_impl() {
824
JavaScriptEventLoop.installGlobalExecutor()

0 commit comments

Comments
 (0)
Please sign in to comment.