Skip to content

Commit fb4dd96

Browse files
Validate npm package structure
1 parent 338c3dd commit fb4dd96

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import fs from "fs/promises";
2+
import path from "path";
3+
import { WASI } from "wasi";
4+
import { RubyVM } from "../dist/index.umd.js";
5+
6+
const initRubyVM = async (rubyModule: WebAssembly.Module, args: string[]) => {
7+
const wasi = new WASI();
8+
const vm = new RubyVM();
9+
const imports = {
10+
wasi_snapshot_preview1: wasi.wasiImport,
11+
};
12+
13+
vm.addToImports(imports);
14+
15+
const instance = await WebAssembly.instantiate(rubyModule, imports);
16+
17+
await vm.setInstance(instance);
18+
19+
wasi.initialize(instance);
20+
vm.initialize();
21+
22+
return {
23+
vm,
24+
wasi,
25+
instance,
26+
};
27+
};
28+
29+
describe("Packaging validation", () => {
30+
jest.setTimeout(20 /*sec*/ * 1000);
31+
32+
test.each([
33+
{ file: "ruby+stdlib.wasm", stdlib: true },
34+
{ file: "ruby.debug.wasm", stdlib: false },
35+
{ file: "ruby.debug+stdlib.wasm", stdlib: true },
36+
])("Load all variants", async ({ file, stdlib }) => {
37+
const binary = await fs.readFile(path.join(__dirname, `./../dist/${file}`));
38+
const mod = await WebAssembly.compile(binary.buffer);
39+
const { vm } = await initRubyVM(mod, ["ruby.wasm", "-e_=0"]);
40+
// Check loading ext library
41+
vm.eval(`require "stringio"`)
42+
if (stdlib) {
43+
// Check loading stdlib gem
44+
vm.eval(`require "English"`)
45+
}
46+
});
47+
48+
});

0 commit comments

Comments
 (0)