Skip to content

Commit b8f6902

Browse files
committed
fix(tests): wait for interface to initialize before starting
1 parent 9bd9920 commit b8f6902

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/test/setup.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ let wasmFunctionTable: WebAssembly.Table // The table of callback functions in t
157157
* Maps request ids to a tuple of the returned data's pointer, and the data's size
158158
*/
159159
const promiseResults = new Map<bigint, [number, number]>()
160-
const failedRequests: bigint[] = [];
160+
const failedRequests: bigint[] = []
161161

162162
wasmInstance = new WebAssembly.Instance(wasmModule, {
163163
wasi_snapshot_preview1: wasiSystem.wasiImport,
@@ -223,20 +223,20 @@ wasmInstance = new WebAssembly.Instance(wasmModule, {
223223
func(requestId, 200, ctx)
224224
})
225225
.catch(err => {
226-
failedRequests.push(requestId);
226+
failedRequests.push(requestId)
227227
})
228228

229229
return requestId
230230
},
231231
fsNetworkHttpRequestGetState: (requestId: bigint) => {
232-
if(failedRequests.includes(requestId)) {
232+
if (failedRequests.includes(requestId)) {
233233
return 4 // FS_NETWORK_HTTP_REQUEST_STATE_FAILED
234234
}
235-
if(promiseResults.has(requestId)) {
235+
if (promiseResults.has(requestId)) {
236236
return 3 // FS_NETWORK_HTTP_REQUEST_STATE_DATA_READY
237237
}
238238
return 2 // FS_NETWORK_HTTP_REQUEST_STATE_WAITING_FOR_DATA
239-
}
239+
},
240240
},
241241
}) as WasmInstance
242242

@@ -290,6 +290,15 @@ beforeAll(async () => {
290290
throw new Error("Please specify the env var `NAVIGATION_DATA_SIGNED_URL`")
291291
}
292292

293+
// Utility function to convert onReady to a promise
294+
const waitForReady = (navDataInterface: NavigraphNavigationDataInterface): Promise<void> => {
295+
return new Promise((resolve, _reject) => {
296+
navDataInterface.onReady(() => resolve())
297+
})
298+
}
299+
300+
await waitForReady(navigationDataInterface)
301+
293302
await navigationDataInterface.download_navigation_data(downloadUrl)
294303
}, 30000)
295304

0 commit comments

Comments
 (0)