Jest cannot find module 'zx/globals' #308
Answered
by
OlaoluwaM
OlaoluwaM
asked this question in
Help needed
-
Expected BehaviorI believe the zx globals should be loaded when running tests with jest on a zx script. Actual BehaviorThe zx/globals module is not found when testing zx scripts. This happens with a TS file as well as a Steps to Reproduce the Problem
Specifications
|
Beta Was this translation helpful? Give feedback.
Answered by
OlaoluwaM
Feb 21, 2022
Replies: 1 comment
-
Reference for anyone who stumbles upon this. @antonmedv seems like the way jest resolves imports for the Here is the solution.TLDRAdd the following to your jest config moduleFileExtensions: [...otherFileExtensionsInYourProject, 'mjs'],
moduleNameMapper: {
"#ansi-styles": "<rootDir>/node_modules/zx/node_modules/chalk/source/vendor/ansi-styles/index.js",
"#supports-color": "<rootDir>/node_modules/zx/node_modules/chalk/source/vendor/supports-color/index.js"
} For the curious
import ansiStyles from '#ansi-styles';
import supportsColor from '#supports-color';
moduleNameMapper: {
"#ansi-styles": "<rootDir>/node_modules/zx/node_modules/chalk/source/vendor/ansi-styles/index.js",
"#supports-color": "<rootDir>/node_modules/zx/node_modules/chalk/source/vendor/supports-color/index.js"
} That's it! Now go test that script :) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
OlaoluwaM
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reference for anyone who stumbles upon this. @antonmedv seems like the way jest resolves imports for the
chalk
lib is rather wonky since thechalk
lib aliases some imports in its package.json, which jest doesn't know about.Here is the solution.
TLDR
Add the following to your jest config
For the curious
.mjs
modules. This is easy to fix using the m…