[v5] jest fails to run
See original GitHub issueI’ve just bumped my code to v5 as I’m currently experiencing the #65 bug often. My tests dont run however (detail below). I’m guessing this is because the current build target
and module
ts settings are super modern.
Could they be downgraded to "target":"es5"
and "module": "commonjs"
?
ps congrats on the first v5 alpha!
● Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
Here's what you can do:
• If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/en/ecmascript-modules for how to enable it.
• To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
• If you need a custom transformation specify a "transform" option in your config.
• If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html
Details:
/home/circleci/project/node_modules/redlock/dist/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import { randomBytes, createHash } from "crypto";
^^^^^^
SyntaxError: Cannot use import statement outside a module
> 1 | import Redlock, { Lock } from "redlock";
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Unable to run jest test case - Stack Overflow
try installing. npm i --save-dev enzyme enzyme-adapter-react-16. Add transform-class-properties to .babelrc file like below -
Read more >vscode-jest - Visual Studio Marketplace
Jest failed to run ; Performance issue? Intermittent errors for (npm/yarn/node) command not found during test run or debugging ...
Read more >Getting all files containing a failed test from a jest run
The following approach is _one way_ to get a list of file names with failed tests after all. You can run jest such...
Read more >test suite failed to run cannot find module jest - You.com
4", "vue-jest": "^5.0.0-alpha.7",. This hint came from a discussion relating to this gist.
Read more >@testing-library/jest-dom - npm
Use this matcher to avoid double negation in your tests. This custom matcher does not take into account the presence or absence of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Jest executes all code in a
vm
, andvm
’s support for ESM is sorta sketchy still (see first link in the error in the OP: https://jestjs.io/docs/ecmascript-modules)Best solution for Jest here is to ship a CJS implementation (in addition to the ESM one) referenced in
main
and usingexports
for the ESM one: https://nodejs.org/api/packages.html#packages_package_entry_points(note that Jest does not support this field yet, which is why
main
is still needed)I just published
v5.0.0-beta.1
which should fix this.