vscode-jest
vscode-jest copied to clipboard
Fails to run test when importing React components -- 'Cannot find module'
Environment
vscode-jest version: [26.6.3]node -v: [14.17.0]npm -voryarn --version: [npm 6.14.13]- your vscode-jest settings if customized:
module.exports ={
moduleNameMapper: {
'\\.(css|scss)$': '<rootDir>/__mocks__/styleMock.js',
'^meteor/(.*)': '<rootDir>/__mocks__/meteorMocks.js'
},
transform: {
'^.+\\.js?$': 'babel-jest'
},
transformIgnorePatterns: ['node_modules/(?!@foobar)/'],
modulePaths:['<rootDir>/ui']
};
- anything else that you think might be relevant? [ ]
babel.config.json:
{
"plugins": ["@babel/plugin-proposal-class-properties",
"@babel/transform-runtime",
"@babel/plugin-proposal-optional-chaining",
["@babel/plugin-proposal-decorators", { "legacy": true }]
],
"presets": [
"@babel/preset-react",
"@babel/preset-env"
]
}
- Operating system: [Ubuntu 20.04.2 LTS]
Prerequisite
- are you able to run jest test from the command line? [No]
- how do you run your tests from the command line? (for example:
npm run testornode_modules/.bin/jest) [npm run test]
Steps to Reproduce
Basically all I'm trying to do is import a module, but after many configurations I've tried none seem to work.
import ElementRenderer from '../ui/components/ElementRenderer';
describe('Something', ()=>{
it('should work', ()=>{
expect(3).toBe(3);
});
});
Expected Behavior
Run a simple test
Actual Behavior
Cannot find module '/ui/components/collectionEditor/utils' from 'ui/components/elements/collections/TablePagination.js'
Require stack:
ui/components/elements/collections/TablePagination.js
ui/components/elements/ChatWidget.js
ui/components/ElementRenderer.js
__tests__/first.test.js
Please note that I'm new to using jest and react, and any light on the issue will be highly appreciated! Thanks!
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...
Hi, this is probably not related to this extension, spawning a jest process from your env. Therefore it requires a working jest env, i.e., able to run jest from your terminal via jest CLI...
Hi @Michael-Sper , were you able to resolve this issue?