-
-
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
[Feature]: Support tc39 "import attributes" #15000
Comments
How are they "not supported"? What breaks? #14345 seems to suggest that the user is already able to use them since tests go through babel. Does this work? Are you using the native ESM support?
|
My project is a TypeScript ESM project:
|
Thanks for the details. What's the exact error you're seeing? Since Jest sees transpiled code, my guess is that the transpiler is misconfigured |
@fregante: The import with the "import attribute" is in an untested file.
|
Yep, that's a babel error, not a Jest/Node one. Just follow the instructions it provides. |
I'm not using As stated by jest in the information written to the terminal along with the error message (see complete content below):
I don't use babel, and don't have any babel configuration file; and I think I should not have to add one just to make jest work with import attributes. It looks like things would have worked if the Proposal: The Additional info: I have now written a test for a module that uses "import attributes". This is the complete informational content written to the terminal when the test fails (I did not include everything in my previous post).
|
I have the same problem. Jest works perfectly with import assert. However, with coverage, the error occurs. I'm using ts-jest. NODE_OPTIONS=--experimental-vm-modules jest --coverage SyntaxError: /swagger.ts: Support for the experimental syntax 'importAttributes' isn't currently enabled (1:47):
Even using ts-jest, I see that the use of babel is fixed in the source. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
@fregante What's happening here? |
Jest uses https://github.com/nicolo-ribaudo/babel-preset-current-node-syntax to know which Babel plugins to enable. If somebody can submit a PR to that repo for import attributes, I can release a new version. |
I just filed nicolo-ribaudo/babel-preset-current-node-syntax#9 which I guess is pretty much the issue equivalent of what @nicolo-ribaudo requested above 😀 |
I published a new minor version of the Babel plugin, this should work now. |
Running into a similar problem, but we use the @babel/plugin-syntax-import-assertions plugin. What is interesting to me, is that if I configure the coverage to not target where to collect (removing collectCoverageFrom) it seems to collect on only the files jest touched when it executed. Since the jest runner tranformed them, it collects properly. It is only the files that jest didn't touch that cause that cause the failure. So my hack workaround is to not specify collectCoverageFrom (resulting in artificially high metrics) @nicolo-ribaudo does your version to the attributes plugin have to be applied to assertions? How do you get babel to use your version as part of the coverage transform? Just yarn adding and getting your new minor version didn't seem to work. |
Make sure to dedupe afterwards so Jest picks up the correct version of the preset |
This is cool to know, and it did indicate it did it -- but it still fails after jest has executed when attempting to collect coverage on files that jest didn't specifically transform. My current understanding is that when jest runs it will use my transform to apply the .babelrc that I have defined, and everything works. But when code coverage has to run and it hits files that babel didn't transform, it attempts to transform on its own using these presets which then fail? idk ... Right now my devDependencies look like this:
And I have run dedupe which did indicate it replaced the old |
- was getting the exact same error as per jestjs/jest#15000
- was getting the exact same error as per jestjs/jest#15000
- was getting the exact same error as per jestjs/jest#15000
- was getting the exact same error as per jestjs/jest#15000
* esm * ts2esm vodoo * bump axios major version for esm support * replace ts-node with tsx * importing json files in esm * refactor: yargs esm * quickfix: downgrade axios to fix type problems with axios-mock-adapter * fix import issues * jest + esm * replace global jest with import.meta.jest - https://jestjs.io/docs/ecmascript-modules#differences-between-esm-and-commonjs * install esbuild * pkg+esbuild * make it possible to run jest without npm run build * manage to get ts-node to work - when using tsx unable to get source-mapping to work * fix npm run test-except-dind * tweak tsconfig * attempt to run npm coverage without building * only way i manage to get npm run coverage to work - was getting the exact same error as per jestjs/jest#15000 * resolve esbuild warning with direct eval * fix `pkg` warnings * docs: update docs * Use @yao-pkg/pkg. Use bin/ instead of pkg/ folder * Upgrade axios * Reintroduce babel-jest * Rename github action job to smoke-test * Use node20 for pkg vm * Fix user-agent --------- Co-authored-by: Mads Jon Nielsen <[email protected]>
🚀 Feature Proposal
I've seen from previous issues that Jest support for import assertions was already added when the proposal was at tc39 stage 3, but that this was reverted/removed again in Feb 2023 as the proposal had been demoted back to stage 2.
Right after this, in March 2023 (more than 1 year back); the proposal went back to stage 3 with a few design changes (keyword
assert
changed towith
), and the of the name of the proposed feature has changed from "import assertions" to "import attributes".Old proposal
New proposal
Import attributes
are now supported in:Our developer team could have written future-proof ECMAScript code, utilizing this upcoming feature - we currently only need it to work with TypeScript and WebPack; but unfortunately it breaks the Jest tests.
When will you add support for import attributes?
Jest is currently our only obstacle...
Motivation
Jest should support the complete ECMAScript module import specs
Example
No response
Pitch
Jest should support the complete ECMAScript module import specs
The text was updated successfully, but these errors were encountered: