【问题标题】:VSCode Launch.json -- Use globally installed jestVSCode Launch.json -- 使用全局安装的 jest
【发布时间】:2020-09-05 18:14:12
【问题描述】:

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

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

我的门票文件夹如下

我希望能够将以下脚本添加到 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 这样的 hack。但这似乎很混乱——如果我在 auth 文件夹中运行测试怎么办?它会工作,但......只是一团糟。

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

你们有什么解决办法吗?非常感谢您的帮助/建议,谢谢!

【问题讨论】:

  • 不应该全局安装 Jest 在没有任何路径的情况下以jest 的形式提供吗?这就是全局安装 NPM 包的目的。

标签: npm visual-studio-code jestjs vscode-debugger


【解决方案1】:

打开终端并将 jest 安装为全局可用的包

$ npm install jest --global

$ jest --version
26.6.3

$ whereis jest
/usr/local/bin/jest

更新你的 launch.json

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

【讨论】:

    猜你喜欢
    • 2021-02-17
    • 1970-01-01
    • 2019-10-05
    • 1970-01-01
    • 1970-01-01
    • 2019-02-03
    • 2019-12-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多