File tree 1 file changed +39
-0
lines changed
Tests/JavaScriptEventLoopTests
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,45 @@ final class WebWorkerTaskExecutorTests: XCTestCase {
200
200
XCTAssertEqual ( Check . countOfInitialization, 2 )
201
201
}
202
202
203
+ func testJSValueDecoderOnWorker( ) async throws {
204
+ struct DecodeMe : Codable {
205
+ struct Prop1 : Codable {
206
+ let nested_prop : Int
207
+ }
208
+
209
+ let prop_1 : Prop1
210
+ let prop_2 : Int
211
+ let prop_3 : Bool
212
+ let prop_7 : Float
213
+ let prop_8 : String
214
+ }
215
+
216
+ let executor = try await WebWorkerTaskExecutor ( numberOfThreads: 1 )
217
+ let task = Task ( executorPreference: executor) {
218
+ let json = """
219
+ {
220
+ " prop_1 " : {
221
+ " nested_prop " : 42
222
+ },
223
+ " prop_2 " : 100,
224
+ " prop_3 " : true,
225
+ " prop_7 " : 3.14,
226
+ " prop_8 " : " Hello, World! "
227
+ }
228
+ """
229
+ let object = JSObject . global. JSON. parse ( json)
230
+ let decoder = JSValueDecoder ( )
231
+ let decoded = try decoder. decode ( DecodeMe . self, from: object)
232
+ return decoded
233
+ }
234
+ let result = try await task. value
235
+ XCTAssertEqual ( result. prop_1. nested_prop, 42 )
236
+ XCTAssertEqual ( result. prop_2, 100 )
237
+ XCTAssertEqual ( result. prop_3, true )
238
+ XCTAssertEqual ( result. prop_7, 3.14 )
239
+ XCTAssertEqual ( result. prop_8, " Hello, World! " )
240
+ }
241
+
203
242
/*
204
243
func testDeinitJSObjectOnDifferentThread() async throws {
205
244
let executor = try await WebWorkerTaskExecutor(numberOfThreads: 1)
You can’t perform that action at this time.
0 commit comments