From eaef1439dd39a2a814326954cdcb9ed3c3111413 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 18 Dec 2023 12:52:46 -0800 Subject: [PATCH 1/2] Add test for ES6 + pthread + node --- test/test_other.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/test_other.py b/test/test_other.py index d26a5173b10c..de15e26af663 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -400,6 +400,18 @@ def test_export_es6_allows_export_in_post_js(self): src = read_file('a.out.js') self.assertContained('export{doNothing};', src) + def test_export_es6_pthread(self): + # Test ES6 + pthreads + running the output in node. + self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6', + '-pthread', '-o', 'hello.mjs']) + # Node requires that we load the module in the following manner (this is + # parallel to the code we emit for HTML in ScriptSource.replacement). + create_file('runner.mjs', ''' + import initModule from "./hello.mjs"; + initModule(); + ''') + self.assertContained('hello, world!', self.run_js('runner.mjs')) + def test_emcc_out_file(self): # Verify that "-ofile" works in addition to "-o" "file" self.run_process([EMCC, '-c', '-ofoo.o', test_file('hello_world.c')]) From 8813f2b78acb6a03a711f2b0bf6f966a55650924 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 18 Dec 2023 15:45:45 -0800 Subject: [PATCH 2/2] refactor --- test/test_other.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/test/test_other.py b/test/test_other.py index de15e26af663..87cd29d19804 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -400,15 +400,18 @@ def test_export_es6_allows_export_in_post_js(self): src = read_file('a.out.js') self.assertContained('export{doNothing};', src) - def test_export_es6_pthread(self): - # Test ES6 + pthreads + running the output in node. + @parameterized({ + '': ([],), + 'pthreads': (['-pthread'],), + }) + def test_export_es6(self, args): self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6', - '-pthread', '-o', 'hello.mjs']) - # Node requires that we load the module in the following manner (this is - # parallel to the code we emit for HTML in ScriptSource.replacement). + '-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 initModule from "./hello.mjs"; - initModule(); + import Hello from "./hello.mjs"; + Hello(); ''') self.assertContained('hello, world!', self.run_js('runner.mjs'))