Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle duplicated manual mock found in the project

Tags:

jestjs

The project has both client app and server site code and once the project is built locally it will put all the built assets both front-end and back-end stuff into build directory and it contains all statics assets client needs to use (all test cases are also included there).

When running the subsequent tests Jest will raise a warning message like below due to duplicated manual mock are existing in multiple directories.

jest-haste-map: duplicate manual mock found:
  Module name: fileMock
  Duplicate Mock path: /Users/x/x/x/x/src/resources/webapp/static/__mocks__/fileMock.js
This warning is caused by two manual mock files with the same file name.
Jest will use the mock file found in:
/Users/x/x/x/x/src/resources/webapp/static/__mocks__/fileMock.js
 Please delete one of the following two files:
 /Users/x/x/x/x/build/classes/webapp/static/__mocks__/fileMock.js
/Users/x/x/x/x/src/resources/webapp/static/__mocks__/fileMock.js
like image 430
X.Creates Avatar asked Sep 20 '18 02:09

X.Creates


2 Answers

Put "<rootDir>/build" inside modulePathIgnorePatterns, the rootDir is not a placeholder but a special token Jest can recognise, https://jestjs.io/docs/en/configuration#rootdir-string

Note that the <rootDir> is NOT a placeholder but a special token Jest uses to identifier the root of your project directory.

    "jest": {
        "modulePathIgnorePatterns": [
            "<rootDir>/build"
        ]
    }

Add the build folder into modulePathIgnorePatterns inside your package.json file.

like image 182
X.Creates Avatar answered Nov 07 '22 15:11

X.Creates


What helped for me was to set roots property. Made test finding much faster.

This is the link from docs https://jestjs.io/docs/en/configuration#roots-arraystring

like image 3
Kirill Groshkov Avatar answered Nov 07 '22 15:11

Kirill Groshkov