使用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的调试面板。
点击调试即可。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM