Skip to content

Commit 231168a

Browse files
Split async eval tests into its own file
1 parent a839198 commit 231168a

File tree

2 files changed

+40
-37
lines changed

2 files changed

+40
-37
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { initRubyVM } from "./init";
2+
3+
describe("Async Ruby code evaluation", () => {
4+
test("async eval over microtasks", async () => {
5+
const vm = await initRubyVM();
6+
const result = await vm.evalAsync(`
7+
require 'js'
8+
o = JS.eval(<<~JS)
9+
return {
10+
async_func: () => {
11+
return new Promise((resolve) => {
12+
queueMicrotask(() => {
13+
resolve(42)
14+
});
15+
});
16+
}
17+
}
18+
JS
19+
o.async_func.await
20+
`);
21+
expect(result.toString()).toBe("42");
22+
});
23+
24+
test("async eval multiple times", async () => {
25+
const vm = await initRubyVM();
26+
vm.eval(`require "js"`);
27+
const ret0 = await vm.evalAsync(`JS.global[:Promise].resolve(42).await`);
28+
expect(ret0.toString()).toBe("42");
29+
const ret1 = await vm.evalAsync(`JS.global[:Promise].resolve(43).await`);
30+
expect(ret1.toString()).toBe("43");
31+
});
32+
33+
test("await outside of evalAsync", async () => {
34+
const vm = await initRubyVM();
35+
const result = vm.eval(
36+
`require "js"; JS.global[:Promise].resolve(42).await`
37+
);
38+
expect(result.call("nil?").toString()).toBe("true");
39+
});
40+
});

packages/npm-packages/ruby-wasm-wasi/test/vm.test.ts

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -192,43 +192,6 @@ eval:11:in \`<main>'`);
192192
hash.call("store", vm.eval(`"key1"`), vm.wrap(new Object()));
193193
});
194194

195-
test("async eval over microtasks", async () => {
196-
const vm = await initRubyVM();
197-
const result = await vm.evalAsync(`
198-
require 'js'
199-
o = JS.eval(<<~JS)
200-
return {
201-
async_func: () => {
202-
return new Promise((resolve) => {
203-
queueMicrotask(() => {
204-
resolve(42)
205-
});
206-
});
207-
}
208-
}
209-
JS
210-
o.async_func.await
211-
`);
212-
expect(result.toString()).toBe("42");
213-
});
214-
215-
test("async eval multiple times", async () => {
216-
const vm = await initRubyVM();
217-
vm.eval(`require "js"`);
218-
const ret0 = await vm.evalAsync(`JS.global[:Promise].resolve(42).await`);
219-
expect(ret0.toString()).toBe("42");
220-
const ret1 = await vm.evalAsync(`JS.global[:Promise].resolve(43).await`);
221-
expect(ret1.toString()).toBe("43");
222-
});
223-
224-
test("await outside of evalAsync", async () => {
225-
const vm = await initRubyVM();
226-
const result = vm.eval(
227-
`require "js"; JS.global[:Promise].resolve(42).await`
228-
);
229-
expect(result.call("nil?").toString()).toBe("true");
230-
});
231-
232195
test("eval encoding", async () => {
233196
const vm = await initRubyVM();
234197
expect(vm.eval(`Encoding.default_external.name`).toString()).toBe("UTF-8");

0 commit comments

Comments
 (0)