使用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