Skip to content

Commit 5028d4f

Browse files
authored
Add webpack test that covers EXPORT_ES6. NFC (#22142)
1 parent db9b1fb commit 5028d4f

File tree

5 files changed

+40
-4
lines changed

5 files changed

+40
-4
lines changed

test/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ def add_on_exit(self, code):
11501150
# libraries, for example
11511151
def get_emcc_args(self, main_file=False, compile_only=False, asm_only=False):
11521152
def is_ldflag(f):
1153-
return any(f.startswith(s) for s in ['-sENVIRONMENT=', '--pre-js=', '--post-js='])
1153+
return any(f.startswith(s) for s in ['-sEXPORT_ES6', '-sPROXY_TO_PTHREAD', '-sENVIRONMENT=', '--pre-js=', '--post-js='])
11541154

11551155
args = self.serialize_settings(compile_only or asm_only) + self.emcc_args
11561156
if asm_only:

test/test_browser.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5541,10 +5541,20 @@ def test_error_reporting(self):
55415541
create_file('post.js', 'throw "foo";')
55425542
self.btest('hello_world.c', args=['--post-js=post.js'], expected='exception:foo')
55435543

5544-
def test_webpack(self):
5545-
shutil.copytree(test_file('webpack'), 'webpack')
5544+
@parameterized({
5545+
'': (False,),
5546+
'es6': (True,),
5547+
})
5548+
def test_webpack(self, es6):
5549+
if es6:
5550+
shutil.copytree(test_file('webpack_es6'), 'webpack')
5551+
self.emcc_args += ['-sEXPORT_ES6']
5552+
outfile = 'src/hello.mjs'
5553+
else:
5554+
shutil.copytree(test_file('webpack'), 'webpack')
5555+
outfile = 'src/hello.js'
55465556
with utils.chdir('webpack'):
5547-
self.compile_btest('hello_world.c', ['-sEXIT_RUNTIME', '-sMODULARIZE', '-sENVIRONMENT=web', '-o', 'src/hello.js'])
5557+
self.compile_btest('hello_world.c', ['-sEXIT_RUNTIME', '-sMODULARIZE', '-sENVIRONMENT=web', '-o', outfile])
55485558
self.run_process(shared.get_npm_cmd('webpack') + ['--mode=development', '--no-devtool'])
55495559
shutil.copyfile('webpack/src/hello.wasm', 'webpack/dist/hello.wasm')
55505560
self.run_browser('webpack/dist/index.html', '/report_result?exit:0')

test/webpack_es6/dist/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<html>
2+
<body>
3+
<hr><div id='output'></div><hr>
4+
<script type="text/javascript" src="main.js"></script>
5+
</body>
6+
</html>

test/webpack_es6/src/index.mjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var params = {
2+
print: (function() {
3+
var element = document.getElementById('output');
4+
return function(text) {
5+
console.log(text);
6+
element.innerHTML += text.replace('\n', '<br>', 'g') + '<br>';
7+
};
8+
})(),
9+
canvas: document.getElementById('canvas'),
10+
};
11+
12+
params.print("testing..");
13+
14+
import Module from './hello.mjs';
15+
Module(params).then((instance) => {
16+
console.log('loaded');
17+
});

test/webpack_es6/webpack.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
entry: "./src/index.mjs",
3+
}

0 commit comments

Comments
 (0)