@@ -2,6 +2,7 @@ import fs from "fs/promises";
2
2
import path from "path" ;
3
3
import { WASI } from "wasi" ;
4
4
import { RubyVM } from "../dist/index.umd.js" ;
5
+ import { DefaultRubyVM } from "../src/node" ;
5
6
6
7
const initRubyVM = async ( rubyModule : WebAssembly . Module , args : string [ ] ) => {
7
8
const wasi = new WASI ( ) ;
@@ -29,12 +30,28 @@ const initRubyVM = async (rubyModule: WebAssembly.Module, args: string[]) => {
29
30
describe ( "Packaging validation" , ( ) => {
30
31
jest . setTimeout ( 20 /*sec*/ * 1000 ) ;
31
32
33
+ const moduleCache = new Map < string , WebAssembly . Module > ( ) ;
34
+ const loadWasmModule = async ( file : string ) => {
35
+ if ( moduleCache . has ( file ) ) {
36
+ return moduleCache . get ( file ) ! ;
37
+ }
38
+ const binary = await fs . readFile ( path . join ( __dirname , `./../dist/${ file } ` ) ) ;
39
+ const mod = await WebAssembly . compile ( binary . buffer ) ;
40
+ moduleCache . set ( file , mod ) ;
41
+ return mod ;
42
+ } ;
43
+
44
+ test ( "DefaultRubyVM" , async ( ) => {
45
+ const mod = await loadWasmModule ( `ruby+stdlib.wasm` ) ;
46
+ const { vm } = await DefaultRubyVM ( mod ) ;
47
+ vm . eval ( `require "stringio"` ) ;
48
+ } )
49
+
32
50
test . each ( [
33
51
{ file : "ruby+stdlib.wasm" , stdlib : true } ,
34
52
{ file : "ruby.debug+stdlib.wasm" , stdlib : true } ,
35
53
] ) ( "Load all variants" , async ( { file, stdlib } ) => {
36
- const binary = await fs . readFile ( path . join ( __dirname , `./../dist/${ file } ` ) ) ;
37
- const mod = await WebAssembly . compile ( binary . buffer ) ;
54
+ const mod = await loadWasmModule ( file ) ;
38
55
const { vm } = await initRubyVM ( mod , [ "ruby.wasm" , "-e_=0" ] ) ;
39
56
// Check loading ext library
40
57
vm . eval ( `require "stringio"` ) ;
@@ -45,10 +62,7 @@ describe("Packaging validation", () => {
45
62
} ) ;
46
63
47
64
test ( "ruby.debug+stdlib.wasm has debug info" , async ( ) => {
48
- const binary = await fs . readFile (
49
- path . join ( __dirname , `./../dist/ruby.debug+stdlib.wasm` )
50
- ) ;
51
- const mod = await WebAssembly . compile ( binary . buffer ) ;
65
+ const mod = await loadWasmModule ( "ruby.debug+stdlib.wasm" ) ;
52
66
const nameSections = WebAssembly . Module . customSections ( mod , "name" ) ;
53
67
expect ( nameSections . length ) . toBe ( 1 ) ;
54
68
} ) ;
0 commit comments