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

Intellij idea IntelliJ IDEA中运行Jest的格式错误的JSON,intellij-idea,jestjs,Intellij Idea,Jestjs,我正在尝试为IntelliJ设置jest配置,但在IDE中遇到此错误未能解析jest config jest.config.js:JSON格式错误: 但是,测试在控制台中工作: ➜ project-web git:(master) ✗ jest --config jest.config.js src/client/components PASS src/client/components/FormInput/index.test.tsx PASS src/client/compone

我正在尝试为IntelliJ设置jest配置,但在IDE中遇到此错误
未能解析jest config jest.config.js:JSON格式错误

但是,测试在控制台中工作:

➜  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配置:

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"],
}
module.exports={
moduleFileExtensions:[“js”、“jsx”、“ts”、“tsx”],
[“moduleNameMapper”]:{
//这些都会处理webpack的别名
[“^Redux(.*)”]:“/src/client/Redux$1”,
[“^Static(.*)”]:“/src/Static$1”,
[“^Components(.*”]:“/src/client/Components$1”,
[“^Hoc(.*)”]:“/src/client/Hoc$1”,
[“^Services(.*”]:“/src/client/Services$1”,
[“^Constants(.*”]:“/src/client/Constants$1”,
[“^Scenes(.*”]:“/src/client/Scenes$1”,
[“^Types(.*”]:“/src/client/Types”,
[“^Helpers(.*”]:“/src/client/Helpers$1”,
//它们负责导入非js资产(这是
//将导入在中指定的对象
//匹配模拟文件而不是资产。对象键充当正则表达式。
[“\\(jpg | jpeg | png | gif | eot | otf | webp | svg | ttf | woff | woff2 | mp4 | webm | wav | mp3 | m4a | aac | oga |)$”]:“/src/| uu mocks |/fileMock.js,
[“\\(css | less)$”]:“/src/\uu mocks\uuu/styleMock.js”
//注意:在上面的正则表达式中,“\\”表示“文字句点”,因为
//斜杠合二为一。
},
//要排除的测试文件。请注意,默认情况下会排除节点_模块,但
//因为我们正在覆盖默认数组,所以必须再次添加它们。
testPathIgnorePatterns:[“/src/build/”,“/node_modules/”,
//转换函数。任何匹配以下正则表达式的文件都将
//与指定函数同步传输**。
转换:{
[“^.+\.(js | jsx | ts | tsx)$”]:“/src/build/test/transformer.js”
},
测试匹配:[
“***测试。(js | jsx | tsx | ts)”
],
模块路径:[“/src/client/”,“/src/static/”,
setupFiles:[“/test/jestSetup.js”],
快照序列化程序:[“酶到json/序列化程序”],
}
如果我没有在IDE的配置中设置配置文件,它将使用默认配置而不是我的
jest.config.js
文件运行测试


谢谢

这在IDE Intellij 2017.3中已修复

我用的是2017.2.6


回答如下:

我也有这个问题。如果我将jest.config.js设置为纯JSON(remove
module.exports=
),我可以在webstorm中运行测试,但是如果在他们的平台中出现问题,我就不能从终端运行测试。我会让你随时了解最新情况。