Skip to content

Commit 77852b5

Browse files
authored
[test] Simplify esm integration tests (#24127)
Output `.mjs` files by default in `-sWASM_ESM_INTEGRATION` mode. Add the `-sWASM_ESM_INTEGRATION` in the `@esm_integration` decorator.
1 parent 00b75d2 commit 77852b5

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

test/common.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,16 +1393,20 @@ def build(self, filename, libraries=None, includes=None, force_c=False, emcc_arg
13931393
assert shared.suffix(filename) != '.c', 'force_c is not needed for source files ending in .c'
13941394
compiler.append('-xc')
13951395

1396+
all_emcc_args = self.get_emcc_args(main_file=True)
1397+
if emcc_args:
1398+
all_emcc_args += emcc_args
13961399
if not output_suffix:
1397-
output_suffix = '.mjs' if emcc_args and '-sEXPORT_ES6' in emcc_args else '.js'
1400+
if '-sEXPORT_ES6' in all_emcc_args or '-sWASM_ESM_INTEGRATION' in all_emcc_args:
1401+
output_suffix = '.mjs'
1402+
else:
1403+
output_suffix = '.js'
13981404

13991405
if output_basename:
14001406
output = output_basename + output_suffix
14011407
else:
14021408
output = shared.unsuffixed_basename(filename) + output_suffix
1403-
cmd = compiler + [filename, '-o', output] + self.get_emcc_args(main_file=True)
1404-
if emcc_args:
1405-
cmd += emcc_args
1409+
cmd = compiler + [filename, '-o', output] + all_emcc_args
14061410
if libraries:
14071411
cmd += libraries
14081412
if includes:

test/test_core.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def esm_integration(func):
4747
def decorated(self, *args, **kwargs):
4848
self.require_node_canary()
4949
self.node_args += ['--experimental-wasm-modules', '--no-warnings']
50+
self.emcc_args += ['-sWASM_ESM_INTEGRATION', '-Wno-experimental']
5051
if self.is_wasm64():
5152
self.skipTest('wasm64 requires wasm export wrappers')
5253
func(self, *args, **kwargs)
@@ -9578,13 +9579,13 @@ def test_wasm_worker_wait_async(self):
95789579

95799580
@esm_integration
95809581
def test_esm_integration_main(self):
9581-
self.do_runf('hello_world.c', 'hello, world!', emcc_args=['-sWASM_ESM_INTEGRATION', '-Wno-experimental'], output_suffix='.mjs')
9582+
self.do_runf('hello_world.c', 'hello, world!')
95829583

95839584
@esm_integration
95849585
def test_esm_integration(self):
95859586
# TODO(sbc): WASM_ESM_INTEGRATION doesn't currently work with closure.
95869587
# self.maybe_closure()
9587-
self.run_process([EMCC, '-o', 'hello_world.mjs', '-sEXPORTED_RUNTIME_METHODS=err', '-sEXPORTED_FUNCTIONS=_main,stringToNewUTF8', '-sWASM_ESM_INTEGRATION', '-Wno-experimental', test_file('core/test_esm_integration.c')] + self.get_emcc_args())
9588+
self.run_process([EMCC, '-o', 'hello_world.mjs', '-sEXPORTED_RUNTIME_METHODS=err', '-sEXPORTED_FUNCTIONS=_main,stringToNewUTF8', test_file('core/test_esm_integration.c')] + self.get_emcc_args())
95889589
create_file('runner.mjs', '''
95899590
import init, { err, stringToNewUTF8, _main, _foo } from "./hello_world.mjs";
95909591
await init({arguments: ['foo', 'bar']});

0 commit comments

Comments
 (0)