Debugging Jest on VS Code

前端 未结 4 1303
北荒
北荒 2021-01-13 07:19

I\'m trying to debug Jest unit tests using VS Code. I have the following config file settings

\"configurations\": [
    {
        \"name\": \"Debug Jest Te         


        
4条回答
  •  时光说笑
    2021-01-13 08:01

    About debugging Jest unit tests using VSCode, create a the following file (path: .vscode/launch.json)

    If you have created your app using create-react-app

      {
          "version": "0.2.0",
          "configurations": [
            {
              "name": "Debug tests watch mode",
              "type": "node",
              "request": "launch",
              "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/react-scripts",
              "args": ["test", "--runInBand", "--no-cache", "--watchAll=true"],
              "cwd": "${workspaceRoot}",
              "protocol": "inspector",
              "console": "integratedTerminal",
              "internalConsoleOptions": "neverOpen"
            }
          ]
        }
    

    If you have created your app from scratch:

       {
          "version": "0.2.0",
          "configurations": [
            {
              "type": "node",
              "request": "launch",
              "name": "Jest watch all tests",
              "program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
              "args": [
                "--verbose",
                "-i",
                "--no-cache",
                "--watchAll"
              ],
              "console": "integratedTerminal",
              "internalConsoleOptions": "neverOpen"
            }
          ]
        }
    

    There are more configurations available, if you need more info check out:

    • Step by step guide (post)
    • Create react app official guide
    • Microsoft official guide

提交回复
热议问题