-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
feat: ESM data uri import and mock #12392
Conversation
Hi @tbossi! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
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.
this is awesome work, thank you so much!
Can you add some tests for static imports (not just dynamic), plus cases where it fails due to malformed scheme or data?
We also need a changelog entry 🙂
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.
yay, this is cool 👍
packages/jest-runtime/src/index.ts
Outdated
if (mime === 'application/json') { | ||
code = 'export default ' + code; | ||
} |
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 think this should use SyntheticModule
rather than SourceTextModule
packages/jest-runtime/src/index.ts
Outdated
} | ||
|
||
const match = specifier.match( | ||
/^data:(?<mime>text\/javascript|application\/json|application\/wasm)(?:;(?<encoding>charset=utf-8|base64))?,(?<code>.*)$/, |
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 we lift this regex to the module level as a constant?
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Co-authored-by: Simen Bekkhus <sbekkhus91@gmail.com>
Co-authored-by: Simen Bekkhus <sbekkhus91@gmail.com>
Codecov Report
@@ Coverage Diff @@
## main #12392 +/- ##
==========================================
- Coverage 68.48% 68.33% -0.15%
==========================================
Files 325 325
Lines 16971 17009 +38
Branches 5061 5072 +11
==========================================
+ Hits 11622 11623 +1
- Misses 5317 5354 +37
Partials 32 32
Continue to review full report at Codecov.
|
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.
this is great, thanks!
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
This change should close #12370
Allows dynamic import (and mock) from
data:
URI as it works on node.js:Test plan
Added e2e tests in native-esm.test.js to check:
jest.unstable_mockModule()
.