Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging Jest on VS Code

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

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

However when I run (F5) VS Code I get the following error

Error: AggregatedResult must be present after test run is complete

Any idea why?

like image 464
tmp dev Avatar asked Nov 30 '17 00:11

tmp dev


People also ask

How to debug jest in Visual Studio Code?

VS Code: Debugging Jest 1 Getting started. The VS Code editor has built-in debugging support for the Node.js runtime and can debug any language transpiled into JavaScript. 2 Start debugging. Open the unit test file you want to debug. ... 3 Another way to debug. ... 4 Jest with Chrome debugger. ... 5 CLI Arguments

How do I debug a unit test in Visual Studio Code?

Read more details about Debugging in VS Code and Node.js debugging in VS Code. Open the unit test file you want to debug. Set breakpoints or the debugger statement where you want to stop. Press Ctrl + Shift + D, or click on the Debug icon in the left panel.

How to integrate jest with VSCode?

Choose nodejs (jest runs under node). A brand new launch.json file will be displayed. We got a launch.json file under the folder .vscode including a default implementation: In the next step we will replace the content of this file with a new one that will let us integrate the editor with Jest.

How to debug launch a chrome instance using jest?

In the screenshot, there is a debug configuration active for launching a Chrome instance. To add a new configuration for Jest, hit the cog on the right side of the Launch Chrome selection. It will open a new tab with file launch.json. Or, you can open command palette and search for "Debug: Open launch.json".


1 Answers

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
like image 72
Braulio Avatar answered Oct 09 '22 11:10

Braulio