@@ -3397,21 +3397,24 @@ def test_jspi_add_function(self):
33973397 self.do_runf('other/test_jspi_add_function.c', 'done')
33983398
33993399 @parameterized({
3400- '': [[]],
3401- 'with_jsgen': [['-sEMBIND_AOT']]
3400+ 'commonjs': [['-sMODULARIZE'], ['--module', 'commonjs', '--moduleResolution', 'node']],
3401+ 'esm': [['-sEXPORT_ES6'], ['--module', 'NodeNext', '--moduleResolution', 'nodenext']],
3402+ 'esm_with_jsgen': [['-sEXPORT_ES6', '-sEMBIND_AOT'], ['--module', 'NodeNext', '--moduleResolution', 'nodenext']]
34023403 })
3403- def test_embind_tsgen (self, opts):
3404+ def test_embind_tsgen_end_to_end (self, opts, tsc_opts ):
34043405 # Check that TypeScript generation works and that the program is runs as
34053406 # expected.
34063407 self.emcc(test_file('other/embind_tsgen.cpp'),
3407- ['-o', 'embind_tsgen.mjs ', '-lembind', '--emit-tsd', 'embind_tsgen.d.ts'] + opts)
3408+ ['-o', 'embind_tsgen.js ', '-lembind', '--emit-tsd', 'embind_tsgen.d.ts'] + opts)
34083409
34093410 # Test that the output compiles with a TS file that uses the defintions.
34103411 shutil.copyfile(test_file('other/embind_tsgen_main.ts'), 'main.ts')
3411- # A package file with type=module is needed to enabled ES modules in TSC and
3412- # also run the output JS file as a module in node.
3413- shutil.copyfile(test_file('other/embind_tsgen_package.json'), 'package.json')
3414- cmd = shared.get_npm_cmd('tsc') + ['embind_tsgen.d.ts', 'main.ts', '--module', 'NodeNext', '--moduleResolution', 'nodenext']
3412+ if '-sEXPORT_ES6' in opts:
3413+ # A package file with type=module is needed to enabled ES modules in TSC and
3414+ # also run the output JS file as a module in node.
3415+ shutil.copyfile(test_file('other/embind_tsgen_package.json'), 'package.json')
3416+
3417+ cmd = shared.get_npm_cmd('tsc') + ['embind_tsgen.d.ts', 'main.ts', '--target', 'es2021'] + tsc_opts
34153418 shared.check_call(cmd)
34163419 actual = read_file('embind_tsgen.d.ts')
34173420 self.assertFileContents(test_file('other/embind_tsgen_module.d.ts'), actual)
0 commit comments