我正在尝试为IntelliJ设置jest配置,但我在IDE Failed to parse Jest config jest.config.js: malformed 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
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
文件运行测试。
由于
答案 0 :(得分:2)