debugging - 无法使用 VS Code 运行 node.js 测试
问题描述
我正在尝试调试一个笑话测试,但似乎没有任何配置正在从 launch.json 运行。只有附加配置有效。
这是我尝试运行的配置示例。
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"${fileBasenameNoExtension}",
"--config"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest.js"
}
}
当我尝试运行此配置时,最终出现以下错误
Message: "ENOENT: no such file or directory, stat '/home/Projects/PublicTransitGraph/node_modules/jest/bin/package.json'"
Stack:
"Error: ENOENT: no such file or directory, stat '/home/Projects/PublicTransitGraph/node_modules/jest/bin/package.json'
at statSync (fs.js:1016:3)\n at AsyncFunction.module.exports.sync (/home/Projects/PublicTransitGraph/node_modules/pkg-dir/node_modules/locate-path/index.js:57:17)
at runMatcher (/home/Projects/PublicTransitGraph/node_modules/pkg-dir/node_modules/find-up/index.js:54:22)
at AsyncFunction.module.exports.sync (/home/Projects/PublicTransitGraph/node_modules/pkg-dir/node_modules/find-up/index.js:67:21)
at AsyncFunction.module.exports.sync (/home/Projects/PublicTransitGraph/node_modules/pkg-dir/index.js:15:26)
at module.exports (/home/Projects/PublicTransitGraph/node_modules/import-local/index.js:7:27)\n at Object.<anonymous> (/home/Projects/PublicTransitGraph/node_modules/jest/bin/jest.js:11:6)
at Module._compile (internal/modules/cjs/loader.js:1137:30)\n at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)"
我已经从 更改为workspaceFolder
,workspaceRoot
但它似乎没有做任何事情。
它似乎正在寻找 jest 模块的 bin 文件夹中的 package.json ,但那里没有。我不知道为什么它在通过命令行运行它时甚至看起来都没有给出错误。
这是我直接从 jest网站获得的另一个配置。
但是当运行这个时,路径显然被错误地附加了,它给了我no such file or directory
错误
{
"name": "Debug Jest Tests",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/jest/bin/jest.js",
"--runInBand"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"port": 9229
}
Message: "ENOENT: no such file or directory, stat '/home/Projects/PublicTransitGraph/node_modules/jest/bin/package.json'"
"Error: ENOENT: no such file or directory, stat '/home/Projects/PublicTransitGraph/node_modules/jest/bin/package.json'
at statSync (fs.js:1016:3)
at AsyncFunction.module.exports.sync (/home/Projects/PublicTransitGraph/node_modules/pkg-dir/node_modules/locate-path/index.js:57:17)
at runMatcher (/home/Projects/PublicTransitGraph/node_modules/pkg-dir/node_modules/find-up/index.js:54:22)
at AsyncFunction.module.exports.sync (/home/Projects/PublicTransitGraph/node_modules/pkg-dir/node_modules/find-up/index.js:67:21)
at AsyncFunction.module.exports.sync (/home/Projects/PublicTransitGraph/node_modules/pkg-dir/index.js:15:26)
at module.exports (/home/Projects/PublicTransitGraph/node_modules/import-local/index.js:7:27)
at Object.<anonymous> (/home/Projects/PublicTransitGraph/node_modules/jest/bin/jest.js:11:6)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)"
解决方案
进行更多研究后,似乎在左侧的断点选项卡中关闭可以Caught Exceptions
解决这两个问题。
推荐阅读
- android - 当应用程序处于后台/最小化时,回调不会触发
- java - 在 Java 中读取 Excel 中的值,Windows 与 Linux 的问题
- grails - 如何设置 grails 代理有错误 & grails install
- python - Django中自定义用户和管理器的正确名称
- visual-studio-code - 模块“ansible.module_utils”中没有名称“xxx”,VScode中的pylint(no-name-in-module)
- azure-webjobs - azure webjobs - '需要会话的实体不可能创建非会话消息接收器
- excel - 查找月份的最后一天
- javascript - highcharts + vue.js 的问题:测量的特定图表
- java - 修改Android Java源码并重新打包成APK文件
- python - 如何处理函数的返回值?