我正在将 Jest 测试用例运行到一个 ReactJS 项目中。我正在尝试在 VS code 中调试我的笑话测试用例。测试在命令行上运行正常。但是当我在 VS Code 中启动调试器时,我看到错误。
启动.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest Tests",
"program": "${workspaceRoot}/xxx/xxx/node_modules/jest/bin/jest",
"args": [
"-i"
],
"internalConsoleOptions": "openOnSessionStart",
"outFiles": [
"${workspaceRoot}/xxx/xxx/**/*"
]
}
]
}
Run Code Online (Sandbox Code Playgroud)
Debugger listening on ws://127.0.0.1:31182/2bf113f1-002f-49ed-ad91-5510affd172a
Debugger attached.
Error: Could not find a config file based on provided values:
path: "/Users/xxx/xxx/xxx-ui"
cwd: "/Users/xxx/xxx/xxx-ui"
Configh paths must be specified by either a direct path to a config
file, or a path to a directory. If directory is given, Jest will try to
traverse directory tree up, until it finds either "jest.config.js" or
"package.json".
Run Code Online (Sandbox Code Playgroud)
只需在启动配置中指定 -c 选项:
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"{$PathToNPMRoot}/node_modules/jest/bin/jest.js",
"--runInBand",
"-c", "{$PathToConfig}/jest.config.js",
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"port": 9229
},
Run Code Online (Sandbox Code Playgroud)
您必须替换 {$PathToNPMRoot} 和 {$PathToConfig}
我会告诉你是什么让我成功的。
正如文档所述,如果您的代码不在项目文件夹的根目录中,您应该创建一个新的配置文件来指定 jest 在 z .vscode 文件夹中的位置,例如:
.vscode/设置.json
{
"jest.pathToJest": "functions/node_modules/.bin/jest"
}
Run Code Online (Sandbox Code Playgroud)
(您应该将“functions”替换为您自己的文件夹名称,如果您的代码位于项目的根目录下,则无需执行上一步)
完成此操作后,即使我正确配置了 jest 的路径并且在 package.json 上正确指定了 jest 配置,然后我将 jest 配置移至根目录下的 jest.config.js 文件,我仍然遇到与您相同的错误我的项目的全部内容,仅此而已,在我使用命令 Jest: Start Runner 后,jest 现在已启动并运行。
//jest.config.js on root dir
module.exports = { verbose: true };
Run Code Online (Sandbox Code Playgroud)
我希望你能让它发挥作用
干杯!
| 归档时间: |
|
| 查看次数: |
11935 次 |
| 最近记录: |