From 5028d4f40b33c97f7fefafc9e9ae2fe39516ebf7 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Tue, 25 Jun 2024 16:16:15 -0700 Subject: [PATCH] Add webpack test that covers EXPORT_ES6. NFC (#22142) --- test/common.py | 2 +- test/test_browser.py | 16 +++++++++++++--- test/webpack_es6/dist/index.html | 6 ++++++ test/webpack_es6/src/index.mjs | 17 +++++++++++++++++ test/webpack_es6/webpack.config.js | 3 +++ 5 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 test/webpack_es6/dist/index.html create mode 100644 test/webpack_es6/src/index.mjs create mode 100644 test/webpack_es6/webpack.config.js diff --git a/test/common.py b/test/common.py index b24747bb658a..0f4e64aa975d 100644 --- a/test/common.py +++ b/test/common.py @@ -1150,7 +1150,7 @@ def add_on_exit(self, code): # libraries, for example def get_emcc_args(self, main_file=False, compile_only=False, asm_only=False): def is_ldflag(f): - return any(f.startswith(s) for s in ['-sENVIRONMENT=', '--pre-js=', '--post-js=']) + return any(f.startswith(s) for s in ['-sEXPORT_ES6', '-sPROXY_TO_PTHREAD', '-sENVIRONMENT=', '--pre-js=', '--post-js=']) args = self.serialize_settings(compile_only or asm_only) + self.emcc_args if asm_only: diff --git a/test/test_browser.py b/test/test_browser.py index 28bd72a0daaa..e668740a9daf 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -5541,10 +5541,20 @@ def test_error_reporting(self): create_file('post.js', 'throw "foo";') self.btest('hello_world.c', args=['--post-js=post.js'], expected='exception:foo') - def test_webpack(self): - shutil.copytree(test_file('webpack'), 'webpack') + @parameterized({ + '': (False,), + 'es6': (True,), + }) + def test_webpack(self, es6): + if es6: + shutil.copytree(test_file('webpack_es6'), 'webpack') + self.emcc_args += ['-sEXPORT_ES6'] + outfile = 'src/hello.mjs' + else: + shutil.copytree(test_file('webpack'), 'webpack') + outfile = 'src/hello.js' with utils.chdir('webpack'): - self.compile_btest('hello_world.c', ['-sEXIT_RUNTIME', '-sMODULARIZE', '-sENVIRONMENT=web', '-o', 'src/hello.js']) + self.compile_btest('hello_world.c', ['-sEXIT_RUNTIME', '-sMODULARIZE', '-sENVIRONMENT=web', '-o', outfile]) self.run_process(shared.get_npm_cmd('webpack') + ['--mode=development', '--no-devtool']) shutil.copyfile('webpack/src/hello.wasm', 'webpack/dist/hello.wasm') self.run_browser('webpack/dist/index.html', '/report_result?exit:0') diff --git a/test/webpack_es6/dist/index.html b/test/webpack_es6/dist/index.html new file mode 100644 index 000000000000..a5e8b18cf27c --- /dev/null +++ b/test/webpack_es6/dist/index.html @@ -0,0 +1,6 @@ + + +

+ + + diff --git a/test/webpack_es6/src/index.mjs b/test/webpack_es6/src/index.mjs new file mode 100644 index 000000000000..31281c791d1e --- /dev/null +++ b/test/webpack_es6/src/index.mjs @@ -0,0 +1,17 @@ +var params = { + print: (function() { + var element = document.getElementById('output'); + return function(text) { + console.log(text); + element.innerHTML += text.replace('\n', '
', 'g') + '
'; + }; + })(), + canvas: document.getElementById('canvas'), +}; + +params.print("testing.."); + +import Module from './hello.mjs'; +Module(params).then((instance) => { + console.log('loaded'); +}); diff --git a/test/webpack_es6/webpack.config.js b/test/webpack_es6/webpack.config.js new file mode 100644 index 000000000000..9a1523ede1fe --- /dev/null +++ b/test/webpack_es6/webpack.config.js @@ -0,0 +1,3 @@ +module.exports = { + entry: "./src/index.mjs", +}