@@ -237,41 +237,57 @@ def test_emcc_generate_config(self):
237237 self .assertContained ('LLVM_ROOT' , config_contents )
238238 os .remove (config_path )
239239
240- def test_emcc_output_mjs (self ):
241- self .run_process ([EMCC , '-o' , 'hello_world.mjs' , test_file ('hello_world.c' )])
242- output = read_file ('hello_world.mjs' )
243- self .assertContained ('export default Module;' , output )
244- # TODO(sbc): Test that this is actually runnable. We currently don't have
245- # any tests for EXPORT_ES6 but once we do this should be enabled.
246- # self.assertContained('hello, world!', self.run_js('hello_world.mjs'))
240+ @parameterized ({
241+ '' : ([],),
242+ 'node' : (['-sENVIRONMENT=node' ],),
243+ })
244+ def test_emcc_output_mjs (self , args ):
245+ create_file ('extern-post.js' , 'await Module();' )
246+ self .run_process ([EMCC , '-o' , 'hello_world.mjs' ,
247+ '--extern-post-js' , 'extern-post.js' ,
248+ test_file ('hello_world.c' )] + args )
249+ src = read_file ('hello_world.mjs' )
250+ self .assertContained ('export default Module;' , src )
251+ self .assertContained ('hello, world!' , self .run_js ('hello_world.mjs' ))
247252
248253 @parameterized ({
249254 '' : (True , [],),
250255 'no_import_meta' : (False , ['-sUSE_ES6_IMPORT_META=0' ],),
251256 })
257+ @node_pthreads
252258 def test_emcc_output_worker_mjs (self , has_import_meta , args ):
259+ create_file ('extern-post.js' , 'await Module();' )
253260 os .mkdir ('subdir' )
254261 self .run_process ([EMCC , '-o' , 'subdir/hello_world.mjs' , '-pthread' , '-O1' ,
262+ '--extern-post-js' , 'extern-post.js' ,
255263 test_file ('hello_world.c' )] + args )
256264 src = read_file ('subdir/hello_world.mjs' )
257265 self .assertContainedIf ("new URL('hello_world.wasm', import.meta.url)" , src , condition = has_import_meta )
258266 self .assertContainedIf ("new Worker(new URL('hello_world.worker.js', import.meta.url))" , src , condition = has_import_meta )
259267 self .assertContained ('export default Module;' , src )
260268 src = read_file ('subdir/hello_world.worker.js' )
261269 self .assertContained ('import("./hello_world.mjs")' , src )
270+ self .assertContained ('hello, world!' , self .run_js ('subdir/hello_world.mjs' ))
262271
272+ @node_pthreads
263273 def test_emcc_output_worker_mjs_single_file (self ):
274+ create_file ('extern-post.js' , 'await Module();' )
264275 self .run_process ([EMCC , '-o' , 'hello_world.mjs' , '-pthread' ,
276+ '--extern-post-js' , 'extern-post.js' ,
265277 test_file ('hello_world.c' ), '-sSINGLE_FILE' ])
266278 src = read_file ('hello_world.mjs' )
267279 self .assertNotContained ("new URL('data:" , src )
268280 self .assertContained ("new Worker(new URL('hello_world.worker.js', import.meta.url))" , src )
281+ self .assertContained ('hello, world!' , self .run_js ('hello_world.mjs' ))
269282
270283 def test_emcc_output_mjs_closure (self ):
284+ create_file ('extern-post.js' , 'await Module();' )
271285 self .run_process ([EMCC , '-o' , 'hello_world.mjs' ,
272- test_file ('hello_world.c' ), '--closure=1' ])
286+ '--extern-post-js' , 'extern-post.js' ,
287+ test_file ('hello_world.c' ), '--closure=1' ])
273288 src = read_file ('hello_world.mjs' )
274289 self .assertContained ('new URL("hello_world.wasm", import.meta.url)' , src )
290+ self .assertContained ('hello, world!' , self .run_js ('hello_world.mjs' ))
275291
276292 def test_export_es6_implies_modularize (self ):
277293 self .run_process ([EMCC , test_file ('hello_world.c' ), '-sEXPORT_ES6' ])
0 commit comments