VS code debugger variables not showing up - jestjs

I am trying to debug a test in vscode.
jest is runner.
Here is my launch configuration.
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest All",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"args": ["--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"sourceMaps": true }
]
}
Using this when i launch the debugger it stops at breakpoint but none of the variables show up in local variable pane.
image

Try this (if u are on windows):
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest All",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": ["--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
}
},
{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"${fileBasenameNoExtension}",
"--config",
"jest.config.js"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
}
}
]
}

Related

Debugger being skipped during gatsby develop process

Help please, I use to be able to place debugger/breakpoints in the build process of gatsby and debug fine but this is no longer working. It ignores the "debugger". Console.log works fine. Heres my lunch.json, it was working with this setting prior but no longer is.
{
"version": "0.2.0",
"configurations": [
{
"name": "Gatsby develop",
"type": "node",
"request": "launch",
"protocol": "inspector",
"program": "${workspaceRoot}/node_modules/gatsby/dist/bin/gatsby",
"args": ["develop"],
"stopOnEntry": false,
"runtimeArgs": ["--nolazy"],
"sourceMaps": false
},
{
"name": "Gatsby build",
"type": "node",
"request": "launch",
"protocol": "inspector",
"program": "${workspaceRoot}/node_modules/gatsby/dist/bin/gatsby",
"args": ["build"],
"stopOnEntry": false,
"runtimeArgs": ["--nolazy"],
"sourceMaps": false
},
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome",
"url": "http://localhost:8000",
"webRoot": "${workspaceFolder}"
}
]
}

In VS Code why does Yarn debug stop at cli.js when Caught Exceptions is enabled?

I'm trying to debug a Jest test and breakpoint at "Caught Exceptions" in VS Code but it stops at /.node/corepack/yarn/1.22.15/lib/cli.js which is irrelevant to me.
I've tried to add several paths to skipFiles in launch.json but no luck so far.
How can I ignore the Yarn/node core files?
Launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "vscode-jest-tests.v2",
"request": "launch",
"runtimeExecutable": "yarn",
"runtimeVersion": "16.13.2",
"program": "jest",
"args": [
"--runInBand",
"--watchAll=false",
"--testNamePattern",
"${jest.testNamePattern}",
"--runTestsByPath",
"${jest.testFile}"
],
"cwd": "${workspaceFolder}/next/",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"windows": {
"program": "jest"
},
"skipFiles": [
"<node_internals>/**/*.js",
"~/.node/**/*.js",
"**/.yarn/**",
"**/node_modules/**",
"**/yarn/**",
]
},
]
}
Adding **/.node/corepack/yarn/** made it ignore those files.
"skipFiles": [
"<node_internals>/**",
"**/node_modules/**",
"**/.node/corepack/yarn/**"
]

Not connected to runtime

I am trying to debug my nodejs code in debug mode, but I am getting the following error in the debug console. Any idea?
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug content-service",
"program": "${workspaceFolder}\\src\\app.js",
"cwd": "${workspaceFolder}\\src",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
{
"type": "node",
"request": "launch",
"name": "Debug test",
"program": "${workspaceFolder}\\src\\node_modules\\lab\\bin\\lab",
"args": [
"--colors",
"${workspaceFolder}\\src\\test\\test.js"
],
"cwd": "${workspaceFolder}\\src",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
it works if I am not in debug mode.

VSCode node debugger

Hi there I am trying to set up breakpoints in VSCode and use the Chrome debugger. My repo has a Node JS server that runs on http://localhost.lmig.com:3000/.
The main npm command that I need to run is npm start.
My node version is 6.10.0. My local os is Mac OSX and I use zsh with NVM. So far my launch.json is this:
configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome",
"url": "http://localhost.lmig.com:3000/",
"webRoot": "${workspaceFolder}"
},{
"type": "node",
"request": "launch",
"name": "Launch via NPM",
"runtimeExecutable": "npm",
"runtimeVersion": "6.10.0",
"runtimeArgs": [
"run-script",
"start",
"--debugger=3000"
],
"port": 3000,
"restart": true,
"protocol": "legacy",
"remoteRoot": "0.0.0.0:3000",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
// "outFiles": ["${workspaceRoot}/build/**/*.js"],
"sourceMaps": true
}
My package.json is this:
It runs the node process in the integrated terminal but still doesn't seem to hit my breakpoints.
Please help
Just providing this as an alternative launch config, but it is what I use.
You may need to change your "protocol" back to legacy... since you're on an older version of node.
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Debug",
"type": "node",
"request": "launch",
"restart": true,
"program": "${workspaceRoot}/bin/www",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"preLaunchTask": "build",
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development",
"PORT": "3000"
},
"console": "internalConsole",
"outputCapture": "std",
"sourceMaps": true,
"protocol": "inspector",
"skipFiles": [
"${workspaceRoot}/node_modules/**/*.js",
"${workspaceRoot}/lib/**/*.js",
"<node_internals>/**/*.js"
],
"internalConsoleOptions": "openOnSessionStart"
}
]
}

debugging typescript in vscode with autorestart

I am setting up a typescript project with node.
I can debug my main.ts file in vs code with this launch.json configuration:
{
"type": "node",
"request": "launch",
"name": "Lancer le programme",
"program": "${workspaceRoot}/src/main.ts",
"outFiles": [
"${workspaceRoot}/dist/**/*.js"
]
}
This works fine but there is no auto restart when I edit main.ts
To implement auto restart, I launch in my project directory tsc --watch, and then this lauch configuration:
{
"type": "node",
"request": "launch",
"name": "nodemon",
"runtimeExecutable": "nodemon",
"runtimeArgs": [
"--debug=5858"
],
"program": "${workspaceRoot}/src/main.ts",
"outFiles": [
"${workspaceRoot}/dist/**/*.js"
],
"restart": true,
"port": 5858,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"sourceMaps": true
},
The above configuration does autorestart when I edit source files, but the vscode debugger doesn't break anymore...
Has anyone achieved : debugging typscript in vscode with autorestart ?
This is my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "nodemon",
"runtimeExecutable": "${workspaceFolder}/node_modules/nodemon/bin/nodemon.js",
"program": "${workspaceFolder}/build/index.js",
"restart": true,
"runtimeArgs": [
"--debug=5858",
"--inspect-brk"
],
"port": 5858,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
]
}
Note that the prop program must indicate compiled js file. In your case it is ${workspaceRoot}/src/main.ts, but should be ${workspaceRoot}/*compile directory eg. build*/main.js.
Also make sure the typescript recompiles the files to the target directory.

Resources