- 
                Notifications
    You must be signed in to change notification settings 
- Fork 3.4k
[tsgen] Expand TS generation test to compile and run a TS file. #22582
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
Conversation
| struct ValObj { | ||
| Foo foo; | ||
| Bar bar; | ||
| std::string string; | 
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.
        
          
                test/test_other.py
              
                Outdated
          
        
      | # 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') | ||
| # 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Can you instead use the .mjs extension?
| shutil.copyfile(test_file('other/embind_tsgen.ts'), 'main.ts') | ||
| # A package file with type=module is needed to allow top level await in TS. | ||
| 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't tsc generate a file called .mjs here I wonder?
Is the package.json file here needed for running tsc or for running the output?
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.
Why doesn't tsc generate a file called
.mjshere I wonder?
They prefer the package approach. IIRC the different extension was somewhat controversial.
Is the package.json file here needed for running
tscor for running the output?
It's also needed for node to run it as an ES module. I've updated the comment.
In the new TS file we can add tests for things where just checking if the definition file compiles is not enough. This will help catch issues like
7e3c1c7    to
    2a31238      
    Compare
  
    | @@ -0,0 +1,168 @@ | |||
| // TypeScript bindings for emscripten-generated code. Automatically generated at compile time. | |||
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 wonder if we should say "Automatically generated by emcc" instead here.
|  | ||
| actual = read_file('embind_tsgen.d.ts') | ||
| self.assertFileContents(test_file('other/embind_tsgen.d.ts'), actual) | ||
| self.assertFileContents(test_file('other/embind_tsgen_module.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.
Why do we have both embind_tsgen.d.ts and embind_tsgen_module.d.ts checked into source control?
Should these two lines move up to 3391 right after the file is first generated?
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.
other/embind_tsgen.d.ts is used by a two other tests, it's the version of the output built without modularize & es6. I could alternatively rename it for the other tests.
In the new TS file we can add tests for things where just checking if the definition file compiles is not enough. This will help catch issues like #22569.