Skip to content

Commit 840e1b5

Browse files
committed
Ensure EXPORT_ES6 is tested on Node.js
1 parent cdbbefa commit 840e1b5

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/preamble.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,8 @@ if (Module['locateFile']) {
649649
#if EXPORT_ES6 && USE_ES6_IMPORT_META && !SINGLE_FILE // in single-file mode, repeating WASM_BINARY_FILE would emit the contents again
650650
} else {
651651
// Use bundler-friendly `new URL(..., import.meta.url)` pattern; works in browsers too.
652-
wasmBinaryFile = new URL('{{{ WASM_BINARY_FILE }}}', import.meta.url).toString();
652+
// FIXME: On Node.js this needs to be wrapped in fileURLToPath.
653+
wasmBinaryFile = new URL('{{{ WASM_BINARY_FILE }}}', import.meta.url).href;
653654
}
654655
#endif
655656

test/test_other.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,24 @@ def test_emcc_generate_config(self):
234234
os.remove(config_path)
235235

236236
def test_emcc_output_mjs(self):
237-
self.run_process([EMCC, '-o', 'hello_world.mjs', test_file('hello_world.c')])
237+
# FIXME: https://github.com/emscripten-core/emscripten/issues/11792
238+
create_file('extern-pre.js', '''
239+
import { dirname } from "path";
240+
import { fileURLToPath } from "url";
241+
import { createRequire } from "module";
242+
const require = createRequire(import.meta.url);
243+
const __dirname = dirname(fileURLToPath(import.meta.url));
244+
''')
245+
# FIXME: locateFile hook should not be necessary
246+
create_file('extern-post.js', '''
247+
await Module({ locateFile: (fileName, scriptDirectory) => scriptDirectory + fileName });
248+
''')
249+
self.run_process([EMCC, '-o', 'hello_world.mjs', test_file('hello_world.c'),
250+
'--extern-pre-js', 'extern-pre.js',
251+
'--extern-post-js', 'extern-post.js'])
238252
output = read_file('hello_world.mjs')
239253
self.assertContained('export default Module;', output)
240-
# TODO(sbc): Test that this is actually runnable. We currently don't have
241-
# any tests for EXPORT_ES6 but once we do this should be enabled.
242-
# self.assertContained('hello, world!', self.run_js('hello_world.mjs'))
254+
self.assertContained('hello, world!', self.run_js('hello_world.mjs'))
243255

244256
@parameterized({
245257
'': (True, [],),

0 commit comments

Comments
 (0)