在IntelliJ IDEA中运行Jest的格式错误的JSON

时间:2017-11-15 13:53:46

标签: intellij-idea jestjs

我正在尝试为IntelliJ设置jest配置,但我在IDE Failed to parse Jest config jest.config.js: malformed JSON中收到此错误: enter image description here

但是,测试在控制台中运行:

➜  project-web git:(master) ✗ jest --config jest.config.js src/client/components
 PASS  src/client/components/FormInput/index.test.tsx
 PASS  src/client/components/Card/index.test.tsx
 PASS  src/client/components/Button/indext.test.tsx
 PASS  src/client/components/StepsBar/components/Step/Step.test.jsx
 FAIL  src/client/components/Help/index.test.tsx

这个IDE配置: IDE configuration

jest.config.js

module.exports = {
  moduleFileExtensions: ["js", "jsx", "ts", "tsx"],
  ["moduleNameMapper"]: {
    // These take care of webpack's alias
    ["^Redux(.*)"]: "<rootDir>/src/client/redux$1",
    ["^Static(.*)"]: "<rootDir>/src/static$1",
    ["^Components(.*)"]: "<rootDir>/src/client/components$1",
    ["^Hoc(.*)"]: "<rootDir>/src/client/hoc$1",
    ["^Services(.*)"]: "<rootDir>/src/client/services$1",
    ["^Constants(.*)"]: "<rootDir>/src/client/constants$1",
    ["^Scenes(.*)"]: "<rootDir>/src/client/scenes$1",
    ["^Types(.*)"]: "<rootDir>/src/client/types",
    ["^Helpers(.*)"]: "<rootDir>/src/client/helpers$1",

    // These take care of imports of non-js assets (which are allowed by
    // webpack, but not by Babel). Will import the object specified in the
    // matching mock file instead of the asset. The object keys act as regex.
    ["\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$"]: "<rootDir>/src/__mocks__/fileMock.js",
    ["\\.(css|less)$"]: "<rootDir>/src/__mocks__/styleMock.js"
    // NOTE: in the regexs above, "\\." means "a literal period" because the two
    // slashes collapse into one.
  },
  // Test files to exclude. Note that node_modules are excluded by default, but
  // because we're overwriting the default array, they must be added again.
  testPathIgnorePatterns: ["<rootDir>/src/build/", "<rootDir>/node_modules/"],

  // Transform functions. Any file matching the following regexs will be
  // transpiled **synchronously** with the specified function.
  transform: {
    ["^.+\\.(js|jsx|ts|tsx)$"]: "<rootDir>/src/build/test/transformer.js"
  },
  testMatch: [
    "**/*.test.(js|jsx|tsx|ts)"
  ],
  modulePaths: ["<rootDir>/src/client/", "<rootDir>/src/static/"],
  setupFiles: ["<rootDir>/test/jestSetup.js"],
  snapshotSerializers: ["enzyme-to-json/serializer"],
}

如果我没有在IDE的配置中设置配置文件,则使用默认配置而不是我的jest.config.js文件运行测试。

由于

1 个答案:

答案 0 :(得分:2)

这已在IDE Intellij 2017.3

中修复

我使用的是2017.2.6

在这里回答:https://youtrack.jetbrains.com/issue/IDEA-182942