11'use strict' ;
22const common = require ( '../common' ) ;
33
4- if ( process . argv [ 2 ] === 'wasi-child' ) {
4+ if ( process . argv [ 2 ] === 'wasi-child-default' ) {
5+ // test default case
56 const fixtures = require ( '../common/fixtures' ) ;
67 const tmpdir = require ( '../common/tmpdir' ) ;
78 const fs = require ( 'fs' ) ;
@@ -30,12 +31,49 @@ if (process.argv[2] === 'wasi-child') {
3031
3132 wasi . start ( instance ) ;
3233 } ) ( ) . then ( common . mustCall ( ) ) ;
34+ } else if ( process . argv [ 2 ] === 'wasi-child-preview1' ) {
35+ // Test version set to preview1
36+ const assert = require ( 'assert' ) ;
37+ const fixtures = require ( '../common/fixtures' ) ;
38+ const tmpdir = require ( '../common/tmpdir' ) ;
39+ const fs = require ( 'fs' ) ;
40+ const path = require ( 'path' ) ;
41+
42+ common . expectWarning ( 'ExperimentalWarning' ,
43+ 'WASI is an experimental feature and might change at any time' ) ;
44+
45+ const { WASI } = require ( 'wasi' ) ;
46+ tmpdir . refresh ( ) ;
47+ const wasmDir = path . join ( __dirname , 'wasm' ) ;
48+ const wasiPreview1 = new WASI ( {
49+ version : 'preview1' ,
50+ args : [ 'foo' , '-bar' , '--baz=value' ] ,
51+ env : process . env ,
52+ preopens : {
53+ '/sandbox' : fixtures . path ( 'wasi' ) ,
54+ '/tmp' : tmpdir . path ,
55+ } ,
56+ } ) ;
57+
58+ // Validate the getImportObject helper
59+ assert . strictEqual ( wasiPreview1 . wasiImport ,
60+ wasiPreview1 . getImportObject ( ) . wasi_snapshot_preview1 ) ;
61+ const modulePathPreview1 = path . join ( wasmDir , `${ process . argv [ 3 ] } .wasm` ) ;
62+ const bufferPreview1 = fs . readFileSync ( modulePathPreview1 ) ;
63+
64+ ( async ( ) => {
65+ const { instance : instancePreview1 } =
66+ await WebAssembly . instantiate ( bufferPreview1 ,
67+ wasiPreview1 . getImportObject ( ) ) ;
68+
69+ wasiPreview1 . start ( instancePreview1 ) ;
70+ } ) ( ) . then ( common . mustCall ( ) ) ;
3371} else {
3472 const assert = require ( 'assert' ) ;
3573 const cp = require ( 'child_process' ) ;
3674 const { checkoutEOL } = common ;
3775
38- function innerRunWASI ( options , args ) {
76+ function innerRunWASI ( options , args , flavor = 'default' ) {
3977 console . log ( 'executing' , options . test ) ;
4078 const opts = {
4179 env : {
@@ -52,7 +90,7 @@ if (process.argv[2] === 'wasi-child') {
5290 ...args ,
5391 '--experimental-wasi-unstable-preview1' ,
5492 __filename ,
55- 'wasi-child' ,
93+ 'wasi-child-' + flavor ,
5694 options . test ,
5795 ] , opts ) ;
5896 console . log ( child . stderr . toString ( ) ) ;
@@ -64,6 +102,7 @@ if (process.argv[2] === 'wasi-child') {
64102 function runWASI ( options ) {
65103 innerRunWASI ( options , [ '--no-turbo-fast-api-calls' ] ) ;
66104 innerRunWASI ( options , [ '--turbo-fast-api-calls' ] ) ;
105+ innerRunWASI ( options , [ '--turbo-fast-api-calls' ] , 'preview1' ) ;
67106 }
68107
69108 runWASI ( { test : 'cant_dotdot' } ) ;
0 commit comments