Test suite failed to run - Cannot find module
See original GitHub issueEnvironment
node -v
: v8.11.3npm -v
: 5.6.0npm ls jest
ornpm ls react-scripts
(if you haven’t ejected):
$ npm ls jest
/Users/hnjoshi/repos/my-app/content/private/react
└── jest@23.3.0
- your vscode-jest settings if customized:
"jest.runAllTestsFirst": false,
"jest.debugMode": true,
"jest.pathToJest": "jest",
"jest.pathToConfig": "/Users/hnjoshi/repos/my-app/content/private/react/package.json"
- Operating system:
MacOS High Sierra, 10.13.6 (17G65)
Prerequisite
- are you able to run jest test from command line? [yes]
- how do yo run your tests from command line?
npm run test
Steps to Reproduce
rootDir/content/private/react/package.json - npm run test works fine from command line
"scripts": {
"test": "jest --no-cache",
"test:coverage": "jest --coverage --no-cache",
"test-watch": "jest --watch",
"watch": "webpack --progress --watch"
},
"jest": {
"cacheDirectory": "cache",
"collectCoverageFrom": [
"**/*.js",
"!**/eslint-plugin-control/**",
"!**/node_modules/**",
"!**/coverage/**",
"!webpack.config.js"
],
"moduleNameMapper": {
"^.+\\.(scss)$": "<rootDir>/__mocks__/styleMock.js"
},
"testRegex": "/__tests__/[^.].*js$",
"setupFiles": [
"<rootDir>/setup-jest.js",
"<rootDir>/__mocks__/localStorageMock.js"
],
"setupTestFrameworkScriptFile": "<rootDir>/setup-adapter.js",
"snapshotSerializers": [
"<rootDir>/node_modules/enzyme-to-json/serializer"
],
"testEnvironment": "jest-environment-jsdom-global"
}
rootDir/content/private/react/components/ - Test files are in this directory
Relevant Debug Info
I think there is some issue with the --include-path
but I could not tell what script is being executed when I save the test file.
Expected Behavior when test file is saved
Tests should pass or fail for all test suites related to changed files in the Output window.
Actual Behavior
FAIL content/private/react/components/User/Details/__tests__/Details-test.js
● Test suite failed to run
Cannot find module 'components/Name' from 'index.js'
1 | import PropTypes from 'prop-types';
2 | import React from 'react';
> 3 | import Name from 'components/Name';
| ^
4 | import Input from 'components/Input';
5 | import {
6 | Form,
at Resolver.resolveModule (../../../../../../../usr/local/lib/node_modules/jest/node_modules/jest-resolve/build/index.js:221:17)
at Object.<anonymous> (components/User/Details/index.js:3:1)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.542s
Ran all test suites related to changed files.
The fastest (and the most fun) way to resolve the issue is to submit a pull-request yourself. If you are interested, feel free to check out the contribution guide, we look forward to seeing your PR…
Issue Analytics
- State:
- Created 5 years ago
- Reactions:6
- Comments:19 (1 by maintainers)
Top Results From Across the Web
typescript - Test suite failed to run Cannot find module or its ...
I solved this by clearing jest cache see this answer here.
Read more >jest test suite failed to run cannot find module - You.com
The weird thing I experienced is, I grepped the package.json files of all modules in my node_modules directory, and couldn't find any core-js...
Read more >Configuring Jest
Jest will run .mjs and .js files with nearest package.json 's type field set to module as ECMAScript Modules.
Read more >Test suite failed to run Cannot find module 'lightning ...
Test suite failed to run Cannot find module 'lightning/messageService' from 'exOppTradelineLists.js. I am getting the above error when i am ...
Read more >Configuring Module Resolution On Typescript and Jest
If you tried running the tests any time until now, it probably failed to run and threw an error: Cannot find module '@/repositories/person'...
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
Try to add this to jest config
@escaton still doesn’t work for me