0xDrTuna
0xDrTuna6mo ago

How to debug tests in Deno on VSCODE

Hello everyone, I am trying to debug a unit test in Deno. I have tried using deno test --inspect-brk and I tried generating a launch.json with the deno extension for vscode. Here is my launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"request": "launch",
"name": "Debug tests",
"autoAttachChildProcesses": true,
"type": "node",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "C:\\Users\\alex0\\.deno\\bin\\deno.EXE",
"runtimeArgs": [
"test",
"--config",
"./deno.jsonc",
"--inspect-brk=127.0.0.1:9229",
"--allow-all"
],
"attachSimplePort": 9229
}
]
}
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"request": "launch",
"name": "Debug tests",
"autoAttachChildProcesses": true,
"type": "node",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "C:\\Users\\alex0\\.deno\\bin\\deno.EXE",
"runtimeArgs": [
"test",
"--config",
"./deno.jsonc",
"--inspect-brk=127.0.0.1:9229",
"--allow-all"
],
"attachSimplePort": 9229
}
]
}
No description
4 Replies
0xDrTuna
0xDrTuna6mo ago
Am I doing something blatantly wrong?
Deno AI Helper
Deno AI Helper6mo ago
Hello! Debugging tests in Deno using VSCode can be done by integrating the Deno extension with the built-in VSCode debugger. To debug your tests, you should create a launch.json configuration that specifies how the debugger should connect to Deno. Based on the documentation, here's a general guide on how to set up your launch.json for debugging Deno tests: 1. Go to the Run and Debug panel in VSCode. 2. Click on "create a launch.json file". 3. Select the Deno option from the available debugger configurations. The configuration will use the --inspect-wait flag if the configured Deno version is greater than 1.29, or --inspect-brk for versions older than 1.29. This ensures that the debugger has a chance to connect to your program and register all the breakpoints specified in the code. Here's an example of what your launch.json might look like for debugging tests:
{
"version": "0.2.0",
"configurations": [
{
"name": "Deno: Test",
"type": "pwa-node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"runtimeArgs": [
"test",
"--inspect-brk",
"--allow-all"
],
"attachSimplePort": 9229
}
]
}
{
"version": "0.2.0",
"configurations": [
{
"name": "Deno: Test",
"type": "pwa-node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"runtimeArgs": [
"test",
"--inspect-brk",
"--allow-all"
],
"attachSimplePort": 9229
}
]
}
Make sure to replace "runtimeExecutable": "deno" with the path to your Deno executable if it's not in your system's PATH. When you run this configuration, it should start the Deno test runner with the --inspect-brk flag, which will pause execution on the first line of code and wait for the debugger to attach. You can then set breakpoints in your test files, and when you continue execution in the debugger, it will stop at those breakpoints. Remember to adjust the runtimeArgs as needed for your specific use case, such as specifying a config
Deno AI Helper
Deno AI Helper6mo ago
file with --config or setting permissions with --allow-* flags. If you encounter any issues, make sure that you have the latest version of the Deno extension for VSCode installed, and that your Deno version is up to date. 🦕
Leokuma
Leokuma5mo ago
I've never debugged tests like that. Not sure how to do it. Have you tried --inspect-wait instead of --inspect-brk? One way it surely works is like this: enable the setting deno.codeLens.test and a "Debug" option should appear right above the tests in your code