File tree 1 file changed +36
-0
lines changed
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -218,6 +218,42 @@ describe("evalCode", () => {
218
218
arena . dispose ( ) ;
219
219
ctx . dispose ( ) ;
220
220
} ) ;
221
+
222
+ test ( "async function" , async ( ) => {
223
+ const ctx = ( await getQuickJS ( ) ) . newContext ( ) ;
224
+ const arena = new Arena ( ctx , { isMarshalable : true } ) ;
225
+
226
+ const consolelog = vi . fn ( ) ;
227
+ arena . expose ( {
228
+ console : {
229
+ log : consolelog ,
230
+ } ,
231
+ } ) ;
232
+
233
+ arena . evalCode ( `
234
+ const someAsyncOperation = async () => "hello";
235
+ const execute = async () => {
236
+ try {
237
+ const res = await someAsyncOperation();
238
+ console.log(res);
239
+ } catch (e) {
240
+ console.log(e);
241
+ }
242
+ };
243
+ execute();
244
+ ` ) ;
245
+ expect ( consolelog ) . toBeCalledTimes ( 0 ) ;
246
+ expect ( arena . executePendingJobs ( ) ) . toBe ( 2 ) ;
247
+
248
+ arena . executePendingJobs ( ) ;
249
+
250
+ expect ( consolelog ) . toBeCalledTimes ( 1 ) ;
251
+ expect ( consolelog ) . toBeCalledWith ( "hello" ) ;
252
+ expect ( arena . executePendingJobs ( ) ) . toBe ( 0 ) ;
253
+
254
+ arena . dispose ( ) ;
255
+ ctx . dispose ( ) ;
256
+ } ) ;
221
257
} ) ;
222
258
223
259
describe ( "expose without sync" , ( ) => {
You can’t perform that action at this time.
0 commit comments