Skip to content

Instantly share code, notes, and snippets.

@CodeTroopers
Created August 8, 2017 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CodeTroopers/8c012b5bceac57b7d00bdada71c07994 to your computer and use it in GitHub Desktop.
Save CodeTroopers/8c012b5bceac57b7d00bdada71c07994 to your computer and use it in GitHub Desktop.
Debug unit tests with Intern 4 from VSCode

Debug unit tests with Intern 4 from VSCode

This document provides an example of how you can configure vscode to debug unit tests with Intern 4.

You will need to edit your .vscode/launch.json in the root of your project and follow the example JSON below. Then edit your package.json file to add the debug script like in the example below.

You can find a configuration sample for Intern 3 here

There is more documentation of the launch.json at Debugging, including if you have a build step that you want to run before launching the debugger.

You should be able to set breakpoints and step through your tests and code.

{
"version": "0.2.0",
"configurations": [{
"type": "node",
"request": "launch",
"name": "Debug tests",
"runtimeExecutable": "npm",
"windows": {
"runtimeExecutable": "npm.cmd"
},
"runtimeArgs": [
"run",
"debug"
],
"port": 5858,
"protocol": "inspector",
"console": "integratedTerminal"
}
]
}
{
...
"scripts": {
"test": "intern",
"debug": "node --inspect=5858 ./node_modules/intern/bin/intern.js"
}
...
}
@daveabes
Copy link

daveabes commented Jan 4, 2019

Breakpoints not being triggered though for either unit or functional.

@slobo
Copy link

slobo commented Mar 2, 2021

Something like this worked for us without having to modify package.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "pwa-node",
            "request": "launch",
            "name": "Debug",
            "runtimeExecutable": "node",
            "runtimeArgs": [
                "--inspect",
                "./node_modules/.bin/intern",
                "config=@firefox",
                "grep=Something"
            ],
            "skipFiles": [
                "<node_internals>/**"
            ],
            "program": "${file}"
        }
    ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment