@@ -2,6 +2,7 @@ import fs from "fs/promises";
22import path from "path" ;
33import { WASI } from "wasi" ;
44import { RubyVM } from "../dist/index.umd.js" ;
5+ import { DefaultRubyVM } from "../src/node" ;
56
67const initRubyVM = async ( rubyModule : WebAssembly . Module , args : string [ ] ) => {
78 const wasi = new WASI ( ) ;
@@ -29,12 +30,28 @@ const initRubyVM = async (rubyModule: WebAssembly.Module, args: string[]) => {
2930describe ( "Packaging validation" , ( ) => {
3031 jest . setTimeout ( 20 /*sec*/ * 1000 ) ;
3132
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+
3250 test . each ( [
3351 { file : "ruby+stdlib.wasm" , stdlib : true } ,
3452 { file : "ruby.debug+stdlib.wasm" , stdlib : true } ,
3553 ] ) ( "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 ) ;
3855 const { vm } = await initRubyVM ( mod , [ "ruby.wasm" , "-e_=0" ] ) ;
3956 // Check loading ext library
4057 vm . eval ( `require "stringio"` ) ;
@@ -45,10 +62,7 @@ describe("Packaging validation", () => {
4562 } ) ;
4663
4764 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" ) ;
5266 const nameSections = WebAssembly . Module . customSections ( mod , "name" ) ;
5367 expect ( nameSections . length ) . toBe ( 1 ) ;
5468 } ) ;
0 commit comments