-
Notifications
You must be signed in to change notification settings - Fork 401
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
Supports dynamic imports in tests #1211
Supports dynamic imports in tests #1211
Conversation
This is untested. @mstange does it work for you on your current work ? |
Thank you!! I'll try it out in a sec. |
Codecov Report
@@ Coverage Diff @@
## master #1211 +/- ##
=======================================
Coverage 75.82% 75.82%
=======================================
Files 144 144
Lines 9321 9321
Branches 2297 2297
=======================================
Hits 7068 7068
Misses 2012 2012
Partials 241 241 Continue to review full report at Codecov.
|
If we want to prefer static import rather than dynamic, then we should probably add comments linking to the issue to add this feature: webpack/webpack#6615 I'm not sure in this use-case what's appropriate. |
Doesn't look like it helps unfortunately :( |
I've found out a few things.
(Do I need to pre-babelize |
It looks like I'm not the first person to run into this, see rustwasm/wasm-bindgen#233 . The "gecko_profiler_demangle" npm package has been created for the target environment "browser", not for the target environment "nodejs". As a result, it's not expected to work in node. And there is no good solution to target both yet. For example, here's how this problem was worked around in the wasm_cmark_parse module: https://github.com/FreeMasen/wasm_cmark_parse/blob/master/pkg/wasm_cmark_parse_bg.js Julien, do you have an idea for how I could make the demangling code to only run in the browser and not under node? |
From what I see, all that the syntax plugin does is accepting dynamic imports, I don't see any transformation done with this plugin. Webpack's tests use wast-loader with this configuration. But I don't think this is necessary for us: wast-loader allows loading text-form of wasm files, which isn't our need. Otherwise Webpack defaults to Another supposition is that Jest supports dynamic import since jestjs/jest#5883... which is in Jest 23. Turns out I just merged the PR #1212 that upgrades Jest, so maybe after a rebase your code will work :) To fully answer your question:
And I do have a question for you: how does it work at runtime ? Does webpack "just work" with the dynamic import ? |
I also found https://github.com/airbnb/babel-plugin-dynamic-import-node, but I think this is primarily for projects that don't use webpack. |
Can you point me to your code that uses a dynamic import at the moment ? It would be easier to try to fix the problem :) Is it #1203 ? |
Yes, it's #1203. |
I've rebased #1203 onto current master and it didn't fix the problem. |
@mstange, I looked closer from your code and read a bit more on jest documentation.
|
I see. I can do that... I just need to get the right URL to fetch (does node support So then the module require will be synchronous, but the functions that I export will need to resolve asynchronously because |
Yeah, I'm not having much luck with getting the URL in the two contexts. In the webpack+browser context, I can use |
I've added a commit onto #1203 that demonstrates what I tried. |
Or you can use the sync API, maybe that's not that bad for this module...
can't you use "./module" for the URL ? But I now realize that means we'll need to copy the file manually... maybe it's just easier to mock the lib... Another option to pack your wasm lib is https://github.com/rustwasm/wasm-pack. Did you look at it yet ? |
There is no sync "fetch" for the browser... or maybe I'm misunderstanding what you're saying?
In the node context: probably. In the browser + webpack context: not sure - webpack will need to know that this file is one that it needs to put into dist/ and add to the service worker cache. |
closing it now that Markus will do it in his other patch |
Fixes #1204