-
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
Add test for ES6 + pthread + node #20939
Conversation
test/test_other.py
Outdated
# parallel to the code we emit for HTML in ScriptSource.replacement). | ||
create_file('runner.mjs', ''' | ||
import initModule from "./hello.mjs"; | ||
initModule(); |
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 am unsure why this initModule
pattern is needed. It is already in use in the codebase as the comment mentions, and it works, so it looks correct. But oddly I can't find an initModule
method anywhere in our codebase or in the node or JS docs..?
@sbc100 @RReverser maybe you know?
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.
Oh, I guess this is just executing the default export from the module? What we used to call "MODULARIZE_INSTANCE"...
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.
The default export is called Module
.. not initModule
and it should return a promise of a module so you would need to await on it.
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.
@kripken is correct. The actual name you bind the default export to doesn't matter / doesn't have to match between import and export sides.
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.
We should perhaps unify this method across all JS module testing we do here in test_core.py
or test_other.py
.
How about maybe a new self.run_js_module('hello.mjs')
that know how to run emscripten-built js modules? (i.e. takes are of building the runner.mjs).
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.
@sbc100 Do we test this in core? All I found is testing in the browser, and some compilation-only tests in other. This is the first non-browser test to actually run EXPORT_ES6
code AFAICT.
With that said I like the idea to add run_js_module
but it would only be used in this one function for now?
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.
If this is the only place we test EXPORT_ES6
so far in test_core.py
then maybe just leave it as is and we can refactor later..
I'm a little surprised that it is!
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.
Yeah, I was surprised too...
My guess is that we couldn't add ES6 testing when our node version was too old. Then we updated node but didn't add testing. But now we can 🚀
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.
In that case maybe just call this test_export_es6
and have a pthread
variant of it?
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.
Good idea, done.
the test will fail if you add
|
@pca006132 do you mean the new test added in this PR? I added the flag you mentioned to it but it still passes for me. Were you adding the flag in some other way?
|
I run it manually, but I think the major difference is that I have a Commands I used: echo "int main() { return 0; }" > hello-world.c
emcc -pthread hello-world.c -s PTHREAD_POOL_SIZE=4 -o hello-world.mjs
echo "import Module from './hello-world.mjs'; Module();" > test.mjs
echo '{"type":"module"}' > package.json
node test.mjs |
@pca006132 I see, thanks. With those steps I get this error in node 18:
I'm actually not very familiar with the module ecosystem in JS, but from that error message I take it that this is some kind of conflict between the |
I think that warning is harmless since in this case you do want to treat the file as a module, right? Best to output to a file that ends in |
It is not a warning, but an error. There is no difference in whether the file ends with
(code from the generated I think And yes it is better to output |
@pca006132 Interesting, looks like we have related logic here: Lines 197 to 201 in 672bc1f
cc @kleisauke who added that quoted code, and also @RReverser who I believe knows this stuff, hopefully together we can find a good plan here (I know little of it myself, I'm afraid). |
The problem seems to be that we don't have the same logic for |
Would it help if (for the time being anyway) we gave our worker.js the |
Maybe, worth a try. TBH until this report I didn't even know that Node.js looked at extensions of workers too. |
Thanks for the tips, an attempt at a fix is in #21041. That seems to resolve things with such a |
This file can be an ES6 module if a package.json file indicates that all files in the directory are. We need to apply the same tricks as we apply to the main JS file in that case, with createRequire etc. We also need to emit the suffix .worker.mjs and not .js, or else node will error. Followup to #20939 and fixes the package.json discussion after that PR landed.
This combination was not tested before.
In fact even running ES6 in node was not tested before (only the browser was).