JavaScript-jest-haste-map:Haste模块命名冲突:{{name}}

时间:2019-06-17 16:56:58

标签: javascript jestjs

运行npm run test时出现以下错误:

jest-haste-map: Haste module naming collision: {{name}}
  The following files share their name; please adjust your hasteImpl:
    * <rootDir>/packages/some-package/templates/js/package.json
    * <rootDir>/packages/some-package/templates/ts/package.json

我的jest.config看起来像

module.exports = {
  collectCoverage: true,
  setupFiles: ['<rootDir>/jest.setup.js'],
  preset: 'ts-jest',
  testEnvironment: 'jsdom',
  collectCoverageFrom: [
    '<rootDir>/packages/**/__tests__/**/*.ts',
    '!<rootDir>/packages/**/templates/**/*.ts',
  ],
  testMatch: [
    '<rootDir>/packages/**/*.test.ts'
  ],
  transform: {
    '^.+\\.js?$': '<rootDir>/node_modules/babel-jest'
  },
  testPathIgnorePatterns: [
    '/node_modules/',
  ],
  coveragePathIgnorePatterns: [
    '/node_modules/',
  ],
  projects: [
    '<rootDir>/packages/*/jest.config.js'
  ]
};

不确定警告是什么,以及如何解决。

1 个答案:

答案 0 :(得分:1)

由于在我的根目录和package.json目录中存在build,因此收到此警告。通过指定只希望Jest在src中寻找测试,就可以摆脱它,方法是将以下内容添加到我的package.json中:

  "jest": {
    "roots": ["src"]
  }