Using v3 ES modules under jest #110
Replies: 3 comments 1 reply
-
please see #105. I cannot provide solutions for a deficiency in a test framework that does not respect node runtime require rules and mutates the global namespace on top of that. If the mapping as-is works for you, cool, but be on a lookout for jest to be properly supporting ES modules and package exports. |
Beta Was this translation helpful? Give feedback.
-
Hey, I managed to find a resolution to this. I am using NestJS, and tearing out Jest would've been a massive pain. I have 2 locations where there is a jest config. 1 in the package.json, and another in the "moduleNameMapper": {
....
"jose(.*)": "<rootDir>/../node_modules/jose/dist/node/cjs/$1.js"
}, This may require slight adjustments depending on very specific testing environments (folder structure in particular), but in general, this works just fine and does not require a 1-line-per-file approach. |
Beta Was this translation helpful? Give feedback.
-
I'm done waiting for these ecosystems to catch up. jose v4.x will be coming out today/tomorrow with only top level named exports that solve all these tools' problems. |
Beta Was this translation helpful? Give feedback.
-
When using the ES module imports (with typescript + babel), the type checking and build works fine, but running under jest gives me errors like
Cannot find module 'jose/jwe/compact/decrypt'
I was able to work around by adding this to my jest config:
Is there a better solution?
Beta Was this translation helpful? Give feedback.
All reactions