VSCode Launch.json-使用全局安装的玩笑

问题描述

我当前的工作空间结构如下

enter image description here

每个文件夹(auth,client,ticket,common)都有自己的node_modules文件夹(我正在编写微服务)。 .vscode文件夹具有launch.json文件

我的票证文件夹如下

enter image description here

我希望能够将以下脚本添加到launch.json

 {
      "type": "node","request": "launch","name": "Jest Current File","program": "${workspaceFolder}/node_modules/.bin/jest","args": [
        "${fileBasenameNoExtension}","--config","${workspaceRoot}/jest.config.js"
      ],"console": "integratedTerminal","internalConsoleOptions": "neverOpen","disableOptimisticBPs": true
    },

即,我希望能够在当前打开的测试文件上使用调试器。

但是,正如您所看到的,我们有

     "program": "${workspaceFolder}/node_modules/.bin/jest",

根工作区文件夹没有node_modules。 Jest在每个微服务中分别安装。

我做了一个像$ {workspaceFolder} /tickets/node_modules/.bin/jest这样的黑客。但这似乎很混乱-如果我在auth文件夹中运行测试该怎么办?可以,但是...有点混乱。

或者,我可以指向我的jest的全局安装...但是我似乎找不到包含它的正确语法(我知道我的全局npm安装软件包在这里:/ usr / local / lib / node_modules)。...

你们有什么解决方案吗?感谢您的帮助/咨询,谢谢!

解决方法

打开一个终端并安装 jest 作为一个全局可用的包

$ npm install jest --global

$ jest --version
26.6.3

$ whereis jest
/usr/local/bin/jest

更新您的launch.json

"program": "/usr/local/bin/jest",