首页 > 解决方案 > 无法使用 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)"

我已经从 更改为workspaceFolderworkspaceRoot但它似乎没有做任何事情。

它似乎正在寻找 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)"


标签: debuggingvisual-studio-code

解决方案


进行更多研究后,似乎在左侧的断点选项卡中关闭可以Caught Exceptions解决这两个问题。


推荐阅读