使用VSCode调试Jest

0. 环境

Node版本:8.12.0
操作系统:windows10

1. 配置launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Debug Jest Tests",
            "type": "node",
            "request": "launch",
            "runtimeArgs": [
                "--inspect-brk",
                "${workspaceRoot}/node_modules/.bin/jest",
                "--runInBand"
            ],
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "port": "9229"
        }
    ]
}

2. package.json里添加代码

"scripts": {
    "debugger": "node --inspect-brk ./node_modules/jest/bin/jest --runInBand --no-cache --no-watchman"
}

3. 启动Jest调试

执行代码

npm run debugger

4. 打断点调试

通过鼠标,或者通过Ctrl+Shift+D进入VSCode的调试面板。
点击调试即可。

posted @ 2018-09-19 20:56  草珊瑚  阅读(3476)  评论(0编辑  收藏  举报