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"
}
...
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 trying to run the debugger in VSCode using Bazel on a C++ application on MacOS 11. When I try to run this, I get the error message : "Could not load source 'testcpp.cc': 'SourceRequest' not supported". I'm not sure what I need to do to resolve this...it compiles and debugs properly on the command line. Here is my BUILD file:
package(
default_visibility = ["//visibility:public"],
)
cc_binary(
name="testcpp",
srcs=["testcpp.cc"],
)
Here is my .vscode/tasks.json file:
{
"version": "2.0.0",
"tasks": [
{
"label": "test dummy app",
"type": "shell",
"command": "bazel build -c dbg --strip=never --spawn_strategy=standalone :testcpp"
},
]
}
And here is my .vscode/launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "cppdbg",
"preLaunchTask": "test dummy app",
"request": "launch",
"program": "${workspaceFolder}/bazel-bin/testcpp",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
]
}
Any help would be appreciated. Thanks!
I have the same problem and the only thing I could find was on this GitHub issue: https://github.com/microsoft/vscode-cpptools/issues/3831
I wasn't able to fix mine that way (maybe because I'm using lldb instead of gdb) but it seems like you should change the current working directory to the executable's and then add the appropriate source file map as written in the last post of the issue.
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"
]
}
]
}
I get this message when I click on a warning. This is a screenshot of the case.
The error reads,
Unable to open 'warning.cpp': Unable to read file
'/Users/dimen/code/C++/Users/dimen/code/C++/warning.cpp'
(Error: Unable to resolve non-existing file
'/Users/dimen/code/C++/Users/dimen/code/C++/warning.cpp').
My script is located in /Users/dimen/code/C++/warning.cpp so vscode reiterates the path for some reason.
I suspected that the linter setting must've been written erroneously but I'm not sure where I should edit. As some side notes,
Using Microsoft's C/C++ extension.
tasks.json have been customized so that all the builds go inside the build folder
I was facing this issue also.
For resolving this issue, I closed the VSCode and again imported folder again as Path of folder got changed in mine conditions.
If this doesn't work, you can uninstall VSCode and then reinstall it.
You need to edit the problemMatcher part of tasks.json so that it has a variable called fileLocation that is set to absolute. Here is an example of what it should look like:
"problemMatcher": {
"base" : "$gcc",
"fileLocation" : "absolute"
}
I hope this helps.
Check this link. It seems to require detailed configurations for the directory. In task.json the problemMatcher takes the file directory as relative so you got repeating path. Setting "fileLocation" to "absolute" works on my laptop.
For me this worked in tasks.json:
{
"tasks": [
{
//"type": "cppbuild",
"label": "build my project",
"command": "/home/user/path/build.bash",
"args": [
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": {
"base": "$gcc",
"fileLocation": "absolute",
},
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
For some reason i had to specifically remove "type": "cppbuild" for it to work.
I fixed this issue by making a change in 'launch.json' file. I changed the value of "cwd" below "name": "(gdb) Launch eds" in "configurations" field. I set it to the absolute path of the folder containing the project. Below is my launch.json file. I'm using VS Code on Ubuntu.
{
// 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": [
{
"name": "(gdb) Launch eds",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build_x86_debug/bin/fcc",
"args": ["-a=${workspaceFolder}/build_x86_debug/bin/", "-d=${workspaceFolder}/build_x86_debug/bin/", "-c=${workspaceFolder}/build_x86_debug/bin/"],
"stopAtEntry": false,
"cwd": "/home/aiden/dev2",
"environment": [{"name": "LD_LIBRARY_PATH", "value": "/usr/lib:${workspaceFolder}/build_x86_debug/bin:${workspaceFolder}/pocolib1.7.5"}],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "Launch",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/build_x86/bin/emvadapter",
"cwd" : "/home/vendor",
"env" : { "LD_LIBRARY_PATH":"/home/vendor/lib" }
},
{
"name": "Unit Tests",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/build_x86/bin/",
"linux": { "cwd": "${workspaceFolder}/vendor"}
}
]
}
I got this too on ApiLogicServer, which uses this feature extensively.
Took a few, but this resolved it by clicking container (lower left) and then rebuild-container:
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