-
Notifications
You must be signed in to change notification settings - Fork 147
jest transform support #706
Comments
What we shipped in v3.1.0 is the beginnings of support. You can use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Thanks for the interest y'all! |
This comment has been minimized.
This comment has been minimized.
Does the v12 release make this work any easier? What would be the recommended way to use Jest with ESM now? |
Any updates? |
It does not unfortunately.
Continuing to use Babel is the way at the moment until I can get to making |
If that's any help here's how I made it work in the build tool I maintain for work. I created a small transformer which has only the job of converting import/export, and tries to do so only if needed : Which is then added as a jest transform (https://github.com/swissquote/crafty/blob/master/packages/crafty-preset-jest/src/index.js#L50) yarn add @swissquote/crafty-preset-jest And adding this to your Jest configuration: {
"transformIgnorePatterns": [],
"transform": {
"[/\\\\]node_modules[/\\\\].+\\.m?js$": "@swissquote/crafty-preset-jest/src/esm-transformer"
}
} |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@jdalton is the following statement still valid?
I'm trying to run a simple spec with:
and
is still afflicting me xD |
I tried to use esm with jest as a loader. I had the following problems, maybe it will help for the next steps. You can find a minimal reproducible case on that repo.
I had to downgrade from [email protected] to [email protected].
Which might be due to the fact that might be due to the fact that the
Those are basic tests ( It is fixable if I use |
A salute to the brave people in this thread. It's amazing/unfortunate that this giant thread (with associated repositories and whatnot) exists, and yet using the amazing I just don't understand why the Jest people won't simply add a |
Is this still the recommendation? jest is the last barrier between converting our entire code base to esm... |
If I understand this correctly, this "issue" is not anymore existing with
the newest Node version which enables ESM modules?
|
The latest version of node now implemented the new module loader. Does it work on Jest? |
From my scans of GitHub threads, it seems like jest has its own require implementation so even on the new experimental module system in node it wasn’t working, but I don’t know for sure and that’s why I was hoping @jdalton might update this thread :) |
Node's ES modules don't solve it at all (they require package.json with "type": "module", require explicit extensions in imports, and they don't allow interop between CJS and ES6 modules). I'm cheering for this to be added @jdalton Maybe you could publish some simplified (or slow) implementation in the meantime? |
@sheerun instead of the Seriously, why does the Node org hate us all so much? Thank god for @jdalton. |
Yeah Node guys are definitely making a mess. The only choice nowadays is ESM, thanks @jdalton. |
What's the suggested solution to work with jest and esm in its current state? |
@bencondon the solution is using jasmine and wait for better times 😂 |
I've been adding this to the top of my jest test files and it works great: const esmImport = require('esm')(module);
const moduleBeingTested = esmImport('../src/module'); E.G. // ./src/add.js
export function add (a,b) {
return a + b;
} // ./test/add.test.js
const esmImport = require('esm')(module);
const add = esmImport('../src/add).add;
describe('add', () => {
it('works as expected', () => {
expect(add(1,1).toBe(2);
});
)}; |
See also the Native support for ES Modules. |
@JakeChampion Tested your suggestion and it works. It doesn't seem to work with |
@JakeChampion is it possible to make your solution work in a Typescript project? |
@the21st No idea as I don't use TypeScript, sorry about that. |
Any idea on how this is coming along? When it will be ready? |
It seems that Jest is trying to make ESM modules natively available. I understand why it is hard to make it available for general usage, but I also cannot understand why you simply cannot |
babel.config.js - done |
I'm collecting some esm + jest + react + enzyme "real world" issues as I'm going here:
https://github.com/kenotron/esm-jest/
esm/esm.js
Line 178 in 33ee0ac
domutils
that is used byjsdom
&htmlparser2
will do silly things like this:https://github.com/fb55/domutils/blob/master/index.js where they loop through all the object keys and start calling ".bind" because they didn't expect something else to inject properties into the object (could be a jest + domutils goober? not necessarily esm??)
Anyway, it's almost there with jest as far as I can tell! If I just hack-patch this stuff conditional around the problematic code, jest works with esm!
The text was updated successfully, but these errors were encountered: