question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

jest-haste-map: duplicate manual mock found when the duplicate is in the build folder

See original GitHub issue

I’m getting a warning from Jest for each manual mock I have, because it appears to be looking in the src directory and in the dist directory where I output my build.

I get the

jest-haste-map: duplicate manual mock found:
  Module name: index
  Duplicate Mock path: /Users/paul.cowan/projects/ds/payments/api/src/__mocks__/index.ts
This warning is caused by two manual mock files with the same file name.
Jest will use the mock file found in:
/Users/paul.cowan/projects/ds/payments/api/src/__mocks__/index.ts
 Please delete one of the following two files:
 /Users/paul.cowan/projects/ds/payments/api/dist/__mocks__/index.js
/Users/paul.cowan/projects/ds/payments/api/src/__mocks__/index.ts

I’ve tried mucking around with the exclude key in my tsconfig.json, but I can’t find a glob pattern that matches all mocks folders.

I.e. "exclude":["**/__mocks__/*"] but it still happens

    rootDir: process.cwd(),
    coverageDirectory: '<rootDir>/.coverage',
    collectCoverageFrom: [
      'src/**/*.{js,jsx,ts,tsx}',
      '!src/**/*.d.ts',
      '!src/**/*.test.*',
      '!src/test/**/*.*',
      '!src/features/**/*.*'
    ],
    setupFiles: ['@ds/common/scripts/tests/setupTests.js', '@ds/common/config/polyfills.js'],
    testMatch: [
      '<rootDir>/src/**/__tests__/**/*.ts?(x)',
      '<rootDir>/src/**/?(*.)(spec|test).ts?(x)',
      '<rootDir>/src/**/*.feature'
    ],
    testEnvironment: 'node',
    testURL: 'http://localhost',
    transform: {
      '^.+\\.(ts|tsx)$': '<rootDir>/../../node_modules/ts-jest/preprocessor.js',
      '^.+\\.feature$': 'gherkin-jest',
      '^.+\\.css$': '@ds/common/jest/cssTransform.js',
      '^.+\\.csv$': '@ds/common/jest/csvTransform.js',
      '^(?!.*\\.(js|jsx|css|json)$)': '@ds/common/jest/fileTransform.js'
    },
    transformIgnorePatterns: ['[/\\\\](node_modules)[/\\\\].+\\.(js|jsx)$'],
    moduleNameMapper: {
      '^react-native$': 'react-native-web'
    },
    moduleFileExtensions: ['web.js', 'js', 'json', 'web.jsx', 'jsx', 'ts', 'tsx', 'feature', 'csv']```

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:14

github_iconTop GitHub Comments

33reactions
v-dakitcommented, May 6, 2019

In jest.config.js add this.

 roots: ['<rootDir>/src'],
15reactions
dagda1commented, Aug 13, 2018

@htbkoo for me the solution was quite easy as I’m using typescript, I just added the __mocks__ folder to the exclude list:

"exclude": ["**/__mocks__/*", "../../node_modules", "build", "src/**/*.test.ts", "src/**/*.test.tsx"]

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to handle duplicated manual mock found in the project
Put "<rootDir>/build" inside modulePathIgnorePatterns , the rootDir is not a placeholder but a special token Jest can recognise, ...
Read more >
Manual Mocks · Jest
Here's a contrived example where we have a module that provides a summary of all the files in a given directory. // FileSummarizer.js...
Read more >
How to handle duplicated manual mock found in the project ...
jest -haste-map: duplicate manual mock found: Module name: fileMock ... Add the build folder into modulePathIgnorePatterns inside your package.json file.
Read more >
jest-haste-map: duplicate manual mock found: next/config
jest will complain if we have more than one manual mock on the same module, even when they are placed in a different...
Read more >
[bug] duplicate manual mock found in separate directories
... I'm given the duplicate manual mock found error from jest-haste-map . If, however, I try to create src/app/modules/__mocks__/{module1.js ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found