Skip to content

Commit

Permalink
[test] Consistent naming of ES module tests. NFC (#23813)
Browse files Browse the repository at this point in the history
Split out from #23175
  • Loading branch information
sbc100 authored Mar 3, 2025
1 parent 004d96c commit 1da9f3a
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def test_emcc_generate_config(self, compiler):
'': ([],),
'node': (['-sENVIRONMENT=node'],),
})
def test_emcc_output_mjs(self, args):
def test_esm(self, args):
self.run_process([EMCC, '-o', 'hello_world.mjs',
'--extern-post-js', test_file('modularize_post_js.js'),
test_file('hello_world.c')] + args)
Expand All @@ -372,7 +372,7 @@ def test_emcc_output_mjs(self, args):
'node': (['-sENVIRONMENT=node'],),
})
@node_pthreads
def test_emcc_output_worker_mjs(self, args):
def test_esm_worker(self, args):
os.mkdir('subdir')
self.run_process([EMCC, '-o', 'subdir/hello_world.mjs',
'-sEXIT_RUNTIME', '-sPROXY_TO_PTHREAD', '-pthread', '-O1',
Expand All @@ -385,7 +385,7 @@ def test_emcc_output_worker_mjs(self, args):
self.assertContained('hello, world!', self.run_js('subdir/hello_world.mjs'))

@node_pthreads
def test_emcc_output_worker_mjs_single_file(self):
def test_esm_worker_single_file(self):
self.run_process([EMCC, '-o', 'hello_world.mjs', '-pthread',
'--extern-post-js', test_file('modularize_post_js.js'),
test_file('hello_world.c'), '-sSINGLE_FILE'])
Expand All @@ -394,40 +394,23 @@ def test_emcc_output_worker_mjs_single_file(self):
self.assertContained("new Worker(new URL('hello_world.mjs', import.meta.url), {", src)
self.assertContained('hello, world!', self.run_js('hello_world.mjs'))

def test_emcc_output_mjs_closure(self):
def test_esm_closure(self):
self.run_process([EMCC, '-o', 'hello_world.mjs',
'--extern-post-js', test_file('modularize_post_js.js'),
test_file('hello_world.c'), '--closure=1'])
src = read_file('hello_world.mjs')
self.assertContained('new URL("hello_world.wasm", import.meta.url)', src)
self.assertContained('hello, world!', self.run_js('hello_world.mjs'))

def test_export_es6_implies_modularize(self):
def test_esm_implies_modularize(self):
self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6'])
src = read_file('a.out.js')
self.assertContained('export default Module;', src)

def test_export_es6_requires_modularize(self):
def test_esm_requires_modularize(self):
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6', '-sMODULARIZE=0'])
self.assertContained('EXPORT_ES6 requires MODULARIZE to be set', err)

@parameterized({
'': ([],),
# load a worker before startup to check ES6 modules there as well
'pthreads': (['-pthread', '-sPTHREAD_POOL_SIZE=1'],),
})
def test_export_es6(self, args):
self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6',
'-o', 'hello.mjs'] + args)
# In ES6 mode we use MODULARIZE, so we must instantiate an instance of the
# module to run it.
create_file('runner.mjs', '''
import Hello from "./hello.mjs";
Hello();
''')

self.assertContained('hello, world!', self.run_js('runner.mjs'))

@parameterized({
'': ([],),
'pthreads': (['-pthread'],),
Expand Down

0 comments on commit 1da9f3a

Please sign in to comment.