必须指定节点Jest
我正在将Jest测试用例运行到reactjs项目中。我正在尝试在VS代码中调试我最好的测试用例。测试可以在命令行上正常运行。但是,当我用VS代码启动调试器时,会看到错误。
Launch.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/**/*"
]
}
]
}
错误
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".
回答如下:我会告诉你这招对我有什么帮助。
如文档所述,如果您的代码不在项目文件夹的根目录中,则应创建一个新的配置文件以指定jest在z .vscode文件夹中的位置,例如:
。vscode / settings.json
{
"jest.pathToJest": "functions/node_modules/.bin/jest"
}
((如果您的代码位于项目的根目录中,则无需执行上一步,您应该将“ functions”替换为您自己的文件夹名称)
这样做之后,即使我正确配置了jest的路径,并且在package.json上正确指定了jest配置,我仍然遇到与您相同的错误,文件放在我项目的根目录中仅此而已,在我使用命令Jest:Start Runner之后,jest现在已经启动并运行。
//jest.config.js on root dir
module.exports = { verbose: true };
我希望你能使它工作欢呼!