【问题标题】:Jest failed to build dependency graph, collision between source and build filesJest 无法构建依赖关系图,源文件和构建文件之间发生冲突
【发布时间】:2016-06-23 12:59:27
【问题描述】:

我正在使用 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

【问题讨论】:

    标签: javascript babeljs jestjs


    【解决方案1】:

    问题是 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
      ],
      ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-22
      • 1970-01-01
      • 2017-04-14
      • 2017-09-25
      • 1970-01-01
      • 1970-01-01
      • 2017-07-24
      • 1970-01-01
      相关资源
      最近更新 更多