Skip to content

Commit

Permalink
Add webpack test that covers EXPORT_ES6. NFC (#22142)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 authored Jun 25, 2024
1 parent db9b1fb commit 5028d4f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 13 additions & 3 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 6 additions & 0 deletions test/webpack_es6/dist/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<body>
<hr><div id='output'></div><hr>
<script type="text/javascript" src="main.js"></script>
</body>
</html>
17 changes: 17 additions & 0 deletions test/webpack_es6/src/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var params = {
print: (function() {
var element = document.getElementById('output');
return function(text) {
console.log(text);
element.innerHTML += text.replace('\n', '<br>', 'g') + '<br>';
};
})(),
canvas: document.getElementById('canvas'),
};

params.print("testing..");

import Module from './hello.mjs';
Module(params).then((instance) => {
console.log('loaded');
});
3 changes: 3 additions & 0 deletions test/webpack_es6/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
entry: "./src/index.mjs",
}

0 comments on commit 5028d4f

Please sign in to comment.