首页 > 解决方案 > 防止 vscode jest 扩展将 cypress 测试解释为 jest 测试

问题描述

我有一个带有 jest(in ./src/components)和 cypress(in ./cypress)测试的 create-react-app 项目。我的package.json文件中有单独的命令来运行两个测试套件,并且一切都按预期工作。

我的问题在于vscode开玩笑扩展 ( orta.vscode-jest),它将我的cypress测试解释为开玩笑测试并尝试运行它们。

标签: reactjsvisual-studio-codejestjscreate-react-appcypress

解决方案


我通过在我的文件中添加一行来解决这个问题.vscode/settings.json,告诉vscodejest 扩展名 ( orta.vscode-jest) 使用正确的 jest 命令

{
  "jest.pathToJest": "npm run test:jest --"
}

命令在test:jestmy 中定义的位置package.json

{
  "scripts: {
    "test:jest": "CI=true react-scripts test",
  }
}

推荐阅读