@@ -10166,21 +10166,44 @@ def test_node_js_run_from_different_directory(self):
10166
10166
10167
10167
# Tests that a pthreads + modularize build can be run in node js
10168
10168
@node_pthreads
10169
- def test_node_js_pthread_module(self):
10169
+ @parameterized({
10170
+ '': (False,),
10171
+ 'es6': (True,),
10172
+ })
10173
+ def test_node_js_pthread_module(self, es6):
10170
10174
# create module loader script
10175
+ if es6:
10176
+ ext = '.mjs'
10177
+ create_file('moduleLoader.mjs', '''
10178
+ import test_module from "./subdir/module.mjs";
10179
+ test_module().then((test_module_instance) => {
10180
+ test_module_instance._main();
10181
+ });
10182
+ ''')
10183
+ else:
10184
+ ext = '.js'
10185
+ create_file('moduleLoader.js', '''
10186
+ const test_module = require("./subdir/module.js");
10187
+ test_module().then((test_module_instance) => {
10188
+ test_module_instance._main();
10189
+ });
10190
+ ''')
10171
10191
ensure_dir('subdir')
10172
- create_file('subdir/moduleLoader.js', '''
10173
- const test_module = require("./module");
10174
- test_module().then((test_module_instance) => {
10175
- test_module_instance._main();
10176
- });
10177
- ''')
10178
10192
10179
10193
# build hello_world.c
10180
- self.run_process([EMCC, test_file('hello_world.c'), '-o', Path( 'subdir/module.js') , '-pthread', '-sPTHREAD_POOL_SIZE=2', '-sMODULARIZE', '-sEXPORT_NAME=test_module', '-sENVIRONMENT=worker,node'] )
10194
+ self.run_process([EMCC, test_file('hello_world.c'), '-o', 'subdir/module' + ext , '-pthread', '-sPTHREAD_POOL_SIZE=2', '-sMODULARIZE', '-sEXPORT_NAME=test_module'] + self.get_emcc_args() )
10181
10195
10182
10196
# run the module
10183
- ret = self.run_js('subdir/moduleLoader.js')
10197
+ ret = self.run_js('moduleLoader' + ext)
10198
+ self.assertContained('hello, world!', ret)
10199
+
10200
+ create_file('workerLoader.js', f'''
10201
+ const {{ Worker, isMainThread }} = require('worker_threads');
10202
+ new Worker('./moduleLoader{ext}');
10203
+ ''')
10204
+
10205
+ # run the same module, but inside of a worker
10206
+ ret = self.run_js('workerLoader.js')
10184
10207
self.assertContained('hello, world!', ret)
10185
10208
10186
10209
@no_windows('node system() does not seem to work, see https://github.com/emscripten-core/emscripten/pull/10547')
0 commit comments