-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[tsgen] Expand TS generation test to compile and run a TS file. #22582
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
brendandahl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import moduleLoader from './embind_tsgen.mjs'; | ||
brendandahl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const module = await moduleLoader(); | ||
|
||
// Test a few variations of passing value_objects with strings. | ||
module.setValObj({ | ||
bar: module.Bar.valueOne, | ||
string: "ABCD", | ||
callback: () => {} | ||
}); | ||
|
||
module.setValObj({ | ||
bar: module.Bar.valueOne, | ||
string: new Int8Array([65, 66, 67, 68]), | ||
callback: () => {} | ||
}); | ||
|
||
const valObj = module.getValObj(); | ||
// TODO: remove the cast below when better definitions are generated for value | ||
// objects. | ||
const valString : string = valObj.string as string; | ||
|
||
// Ensure nonnull pointers do no need a cast or nullptr check to use. | ||
const obj = module.getNonnullPointer(); | ||
obj.delete(); | ||
|
||
console.log('ts ran'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "index", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "main.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "" | ||
brendandahl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3365,12 +3365,16 @@ def test_jspi_add_function(self): | |
def test_embind_tsgen(self, opts): | ||
# Check that TypeScript generation works and that the program is runs as | ||
# expected. | ||
self.do_runf('other/embind_tsgen.cpp', 'main ran', | ||
emcc_args=['-lembind', '--emit-tsd', 'embind_tsgen.d.ts'] + opts) | ||
self.emcc(test_file('other/embind_tsgen.cpp'), | ||
['-o', 'embind_tsgen.mjs', '-lembind', '--emit-tsd', 'embind_tsgen.d.ts'] + opts) | ||
|
||
# Test that the output compiles with a TS file that uses the defintions. | ||
cmd = shared.get_npm_cmd('tsc') + ['embind_tsgen.d.ts', '--noEmit'] | ||
shutil.copyfile(test_file('other/embind_tsgen.ts'), 'main.ts') | ||
brendandahl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# A package file with type=module is needed to allow top level await in TS. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you instead use the |
||
shutil.copyfile(test_file('other/embind_tsgen_package.json'), 'package.json') | ||
cmd = shared.get_npm_cmd('tsc') + ['embind_tsgen.d.ts', 'main.ts', '--module', 'NodeNext', '--moduleResolution', 'nodenext'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why doesn't tsc generate a file called Is the package.json file here needed for running |
||
shared.check_call(cmd) | ||
self.assertContained('main ran\nts ran', self.run_js('main.js')) | ||
|
||
actual = read_file('embind_tsgen.d.ts') | ||
self.assertFileContents(test_file('other/embind_tsgen.d.ts'), actual) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed this to be a more realistic use of a ValueObject.