Jest无法构建依赖图,源文件和构建文件之间的冲突

时间:2016-03-09 08:42:58

标签: javascript babeljs jestjs

我使用babel将文件从src转换为lib,当我尝试运行jest时,src/Template.jslib/Template.js之间发生冲突

Using Jest CLI v0.9.0, jasmine2, babel-jest

Error: Failed to build DependencyGraph: @providesModule naming collision:
Duplicate module name: Template
Paths: src/Template.js collides with lib/Template.js

如何处理这种情况?有没有办法忽略其中一个目录?

在package.json中:

  • babel-cli@6.x
  • babel-jest@9.x
  • babel-polyfill@6.x
  • babel-preset-es2015@6.x
  • babel-preset-react@6.x
  • jasmine@2.x
  • jasmine-spec-reporter@2.x
  • jest-cli@0.9.x

1 个答案:

答案 0 :(得分:0)

问题是,jest默认搜索整个项目进行测试。 https://facebook.github.io/jest/docs/api.html#config-testpathdirs-array-string

package.json中的解决方案

"jest": {
  "testPathDirs": [
    "<rootDir>/__tests__", # Default is <rootDir>
    "<rootDir>/lib" # Needed for automatic mocking to work
  ],
  ...
}