What does the launch.json look like to run oclif project tests in debug mode? I can't seem to get it so that I set breakpoints and step in.
This launch.json config works for me:
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"runtimeExecutable": "${workspaceFolder}/node_modules/ts-mocha/bin/ts-mocha",
"args": [
"${workspaceFolder}/test/**/*.ts"
],
"protocol": "inspector"
},
I benefitted from the response provided here:
https://github.com/oclif/oclif/issues/135#issuecomment-403622999
I've tested it with typescript, and program works great for debugging.
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/bin/run",
"args": [
"--name",
"Callum",
"--force",
"argument"
]
}
]
}
Related
After some path changes due to being a git submodule, I was able to configure a launch.json and tasks.json to get my application running in debug mode. Here are the tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "docker-build",
"label": "docker-build",
"platform": "python",
"dockerBuild": {
"tag": "signmeasures:latest",
"dockerfile": "${workspaceFolder}/signmeasures-frontend/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
}
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": [
"docker-build"
],
"python": {
"args": [
"runserver",
"0.0.0.0:8000",
"--nothreading",
"--noreload"
],
"file": "signmeasures-frontend/signmeasures/manage.py"
}
}
]
}
and here is the launch.json
{
"configurations": [
{
"name": "Docker: Python - Django",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"python": {
"pathMappings": [
{
"localRoot": "${workspaceFolder}/signmeasures-frontend",
"remoteRoot": "/app"
}
],
"projectType": "django",
"port": 5678,
"host": "localhost"
},
}
]
}
I'm not too familiar with setting up the debug container or docker in general, I'm still trying to learn. When I hit the debug button on the debug tab, it builds a container and then in the debug console I see this
but when I try to go to localhost:8000 it does not load the web app. It shows this:
I'm not sure what I need to change to be able to reach it and set breakpoints to debug this application. What should I do to be able to reach it and debug?
[I'm getting this error][1]
Can't find Node.js binary "node": path does not exist. make sure not.js is installed and in your path or set the runtime executable in your launch.json
[my launch.json is ][2]
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\app.js"
}
]
}
I want to run tests against my AWS environment using a run configuration in vscode.
The tests need access to the AWS account to retrieve information like the name of a bucket, a user pool id ..
I have my credentials configured in ~/.aws/credentials under [dev-user] like:
[dev-user]
aws_access_key_id=*************
aws_secret_access_key=***************************************
I can run this from the command line with export AWS_PROFILE=dev-user and then npm run test.
How do I create a launch config in vscode that does the same? Currently it is not working. I've tried the following: adding env variables or a prelaunch task. But neither of them work:
Env vars:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "vscode-jest-tests",
"request": "launch",
"args": ["--runInBand"],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"internalConsoleOptions": "openOnSessionStart",
"disableOptimisticBPs": true,
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"env": { "AWS_PROFILE": "dev-user"}
}
]
}
Pre launch task:
launch.json
{
"version": "2.0.0",
"configurations": [
{
"type": "node",
"name": "vscode-jest-tests",
"request": "launch",
"args": ["--runInBand"],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"preLaunchTask": "setProfile",
"internalConsoleOptions": "openOnSessionStart",
"disableOptimisticBPs": true,
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "setProfile",
"command": "export AWS_PROFILE=dev-user",
"args": ["test"],
"type": "shell"
}
]
}
None of the above gives me access to the AWS account from my tests.
How do I need to configure launch.json and / or tasks.json to get access to the AWS account in my tests?
It turns out that adding "env": { "AWS_PROFILE": "dev-user"} to your configuration in launch.json does work.
So this is correct:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"name": "vscode-jest-tests",
"request": "launch",
"args": ["--runInBand"],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"internalConsoleOptions": "openOnSessionStart",
"disableOptimisticBPs": true,
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"env": { "AWS_PROFILE": "dev-user"}
}
]
}
I don't know if it will help anyone, but for me I had a key and password that should be sent in the request, I downloaded aws plugin and it didn't work, searching a lot I managed to solve it, you will have to post vscode and edit the launch file, the vscode has "env" property for variables .... I did it like this:
....
env": {
"AWS_DEFAULT_REGION":"xxxxxx",
"AWS_ACCESS_KEY_ID":"xxxxxxxxxxxx",
"AWS_SECRET_ACCESS_KEY":"xxxxxxxxxxxxxxxxxx"
}
...
I'm debugging with Visual Studio Code Version 1.34.
I've setup a breakpoint that is not reached because of exceptions that are not critical.
How do I stop that behaviur? I'm coping the configuration file for debugging with Django in VSC.
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": [
{
"type": "extensionHost",
"request": "launch",
"name": "Launch Extension",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "npm"
},
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}\\manage.py",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"django": true
}
]
}
In python you can use a try and except
If you know the exception that is being thrown:
try:
with open('file.txt') as file:
read_data = file.read()
except FileNotFoundError as fnf_error:
print(fnf_error)
print('this will still be executed')
If you don't know what type of exception is thrown:
try:
function_that_throws()
except:
print('caught exception')
print('this is still executed')
On my Windows machine, I have Visual Studio Code installed. To run tests manually, I go in console to projects folder and enter
go test main_test.go
It works perfectly.
But I have a situation in which I need to debug my test to understand what's going on.
For this I open launch.json and add a configuration
{
"name": "Tests",
"type": "go",
"request": "launch",
"mode": "test",
"remotePath": "",
"port": 2346,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": [
"main_test.go"
],
"showLog": true
}
After I press F5 I have
2017/03/29 13:28:11 server.go:73: Using API v1
2017/03/29 13:28:11 debugger.go:68: launching process with args: [./debug.test main_test.go main_go]
not an executable file
Process exiting with code: 1
Any ideas why this error occurs and what executable it's looking for?
To launch debugger for test I added one more configuration for launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Code",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": [],
"showLog": true
},
{
"name": "Test Current File",
"type": "go",
"request": "launch",
"mode": "test",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${file}",
"env": {},
"args": [],
"showLog": true
}
]
}
Also this configuration does not support tags. All tags in test files have to be disabled
// +build unit
...
For the mode, you can select auto which would choose either debug or test depending on active editor window.
All options for mode are auto, debug, test, exec, replay, core.
The resulting launch.json would look like:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${file}"
}
]
}
In my case it was not working because I named my file main_tests.go instead of main_test.go