@@ -138,41 +138,48 @@ suite('Bindings', () => {
138138 test ( name , async ( ) => {
139139 const source = await readFile (
140140 new URL ( `./cases/${ name } /source.js` , import . meta. url ) ,
141- 'utf8'
141+ 'utf8' ,
142142 ) ;
143143
144+ const test = await import ( `./cases/${ name } /test.js` ) ;
145+
146+ // Determine the relevant WIT world to use
144147 let witWorld ,
145148 witPath ,
146149 worldName ,
147150 isWasiTarget = false ;
148- try {
149- witWorld = await readFile (
150- new URL ( `./cases/${ name } /world.wit` , import . meta. url ) ,
151- 'utf8'
152- ) ;
153- } catch ( e ) {
154- if ( e ?. code == 'ENOENT' ) {
155- try {
156- isWasiTarget = true ;
157- witPath = fileURLToPath (
158- new URL ( `./cases/${ name } /wit` , import . meta. url )
159- ) ;
160- await readdir ( witPath ) ;
161- } catch ( e ) {
162- if ( e ?. code === 'ENOENT' ) {
163- witPath = fileURLToPath ( new URL ( './wit' , import . meta. url ) ) ;
164- worldName = 'test2' ;
165- } else {
166- throw e ;
151+ if ( test . worldName ) {
152+ witPath = fileURLToPath ( new URL ( './wit' , import . meta. url ) ) ;
153+ worldName = test . worldName ;
154+ isWasiTarget = true ;
155+ } else {
156+ try {
157+ witWorld = await readFile (
158+ new URL ( `./cases/${ name } /world.wit` , import . meta. url ) ,
159+ 'utf8' ,
160+ ) ;
161+ } catch ( e ) {
162+ if ( e ?. code == 'ENOENT' ) {
163+ try {
164+ isWasiTarget = true ;
165+ witPath = fileURLToPath (
166+ new URL ( `./cases/${ name } /wit` , import . meta. url ) ,
167+ ) ;
168+ await readdir ( witPath ) ;
169+ } catch ( e ) {
170+ if ( e ?. code === 'ENOENT' ) {
171+ witPath = fileURLToPath ( new URL ( './wit' , import . meta. url ) ) ;
172+ worldName = 'test2' ;
173+ } else {
174+ throw e ;
175+ }
167176 }
177+ } else {
178+ throw e ;
168179 }
169- } else {
170- throw e ;
171180 }
172181 }
173182
174- const test = await import ( `./cases/${ name } /test.js` ) ;
175-
176183 const enableFeatures = test . enableFeatures || [ 'http' ] ;
177184 const disableFeatures =
178185 test . disableFeatures ||
@@ -229,14 +236,14 @@ suite('Bindings', () => {
229236
230237 await writeFile (
231238 new URL ( `./output/${ name } .component.wasm` , import . meta. url ) ,
232- component
239+ component ,
233240 ) ;
234241
235242 for ( const file of Object . keys ( files ) ) {
236243 let source = files [ file ] ;
237244 await writeFile (
238245 new URL ( `./output/${ name } /${ file } ` , import . meta. url ) ,
239- source
246+ source ,
240247 ) ;
241248 }
242249
0 commit comments