我有一个React应用程序,它由CRA使用打字稿创建。我在tsconfig.json中定义了几个模块映射器
2019-07-04T09:53:04-07:00 The content
2019-07-04T10:15:37-07:00 I'm actually
2019-07-04T10:15:37-07:00 Interested on
tsconfig.path.json
然后我在{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@constants/*": ["constants/*"],
"@components/*": ["components/*"],
"@grid/*": ["components/Grid/*"],
"@grid-share/*": ["components/Grid/Share/*"],
"@utils/*": ["util/*"],
"@services/*": ["Services/*"]
}
},
"extends": "../tsconfig.json"
}
中为package.json
定义相同的别名
JEST
当我使用 "jest": {
"snapshotSerializers": [
"enzyme-to-json/serializer"
],
"moduleNameMapper": {
"@constants/(.*)": "<rootDir>/src/constants/$1",
"@utils/(.*)": "<rootDir>/src/util/$1",
"@grid-share/(.*)": "<rootDir>/src/components/Grid/Share/$1",
"@grid/(.*)": "<rootDir>/src/components/Grid/$1",
"@services/(.*)": "<rootDir>/src/Services/$1",
"@components/(.*)": "<rootDir>/src/components/$1"
}
},
时,一切都很好。但是,我想在vs代码中调试测试,我的VSCode午餐盒配置文件如下所示:
yarn test
问题是当我尝试在VSCode中调试测试用例时,出现以下错误
开箱即用,Create React App仅支持覆盖这些Jest 选项:
•collectCoverageFrom•coverageReporters•coverageThreshold
•extraGlobals•globalSetup•globalTeardown•resetMocks• resetModules•snapshotSerializers•watchPathIgnorePatterns。package.json Jest配置中的这些选项不是 Create React App当前支持的
•moduleNameMapper
如果您想覆盖其他Jest选项,则需要从 默认设置。您可以通过运行npm run exit来做到这一点,但请记住 这是单向操作。您也可以向 创建React App讨论开箱即用的更多支持。
没有{
"version": "0.2.0",
"configurations": [{
"name": "Debug All Tests",
"type": "node",
"request": "launch",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
"args": [
"test",
"--runInBand",
"--no-cache",
"--watchAll=false"
],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}, {
"name": "Debug Current Test",
"type": "node",
"request": "launch",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
"args": [
"test",
"--runInBand",
"--no-cache",
"${fileBasenameNoExtension}",
"--watchAll=true"
],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}]
}
,有什么方法可以解决这个问题?