vscode-jest icon indicating copy to clipboard operation
vscode-jest copied to clipboard

Fails to run test when importing React components -- 'Cannot find module'

Open Michael-Sper opened this issue 4 years ago • 2 comments

Environment

  1. vscode-jest version: [26.6.3]
  2. node -v: [14.17.0]
  3. npm -v or yarn --version: [npm 6.14.13]
  4. 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"

]
}
  1. 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 test or node_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...

Michael-Sper avatar May 18 '21 15:05 Michael-Sper

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...

connectdotz avatar May 29 '21 21:05 connectdotz

Hi @Michael-Sper , were you able to resolve this issue?

hrupesh avatar Nov 28 '22 13:11 hrupesh