Debugging in VS Code using Jasmine framework (for Protractor) - visual-studio-code

I'm trying to debug in VS Code.
I've created the launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/conf/conf.js",
}
]
}
I'm using Jasmine and in my conf.js file (I'm using the file from the example when I installed Protractor), it starts with exports.config = { but it has 3 dots showing under it. When I click on the light bulb, it says "Convert to ES6 Module"
When I debug, it doesn't step into the code and just jumps to the end, even if I put breakdowns.
My conf.js file:
exports.config = {
directConnect: true,
capabilities: {
'browserName': 'chrome'
},
framework: 'jasmine',
specs: ['../specs/horses.js'],
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
},
};
When I run: protractor .\conf\conf.js in the Terminal, it works fine.
I have a non-angular page.

Update
I misunderstood your original question so here is a config that should work. Basically the program property needs to point to protractor and you pass your conf.js using the args property
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/node_modules/protractor/bin/protractor",
"args": ["${workspaceRoot}/conf/conf.js"],
"outFiles": [ "${workspaceRoot}/out/*.js" ]
}
]
}
See this article and this previous question for more information.
Original Incorrect Ans
The config file is exporting an object and therefore only has one action that can be debugged and that is export of the config object itself. The properties you are exporting, like specs, jasmineNodeOptions are called at different times during the setup process when protractor launches and not actually doing anything at the time they are exported. If you introduced some executable code in a lifecycle hook, like a beforeLaunch or onPrepare and tried to debug that it would likely work as you are expecting

Related

VSCode - How to specify which project to debug - Azure Functions

My question is a noobie question.
I have an azure function app project, along with a test project. Initially, I start with just the function application project and then I just recently re-org the project folders and added the associated test.csproj
The folder structure I have right now looks like this:
Since moving the function app into the "src" folder, when I want to just run locally, I make sure that from my powershell terminal, I do the following:
cd src
func start
And everything works really well. But if I want to step through the code / debug, hitting F5 doesn't work because it doesn't know which project I'm trying to debug.
Can you tell me how I can debug either project from the parent folder that I'm in ?
I've tried to change my launch.json from this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to .NET Functions",
"type": "coreclr",
"request": "attach",
"processId": "${command:azureFunctions.pickProcess}"
}
]
}
To this:
{
"version": "0.2.0",
"configurations": [
{
"name": "FunctionApp",
"type": "coreclr",
"request": "attach",
"processId": "${command:azureFunctions.pickProcess}",
"program": "${workspaceFolder}/src/bin/Debug/net6.0/bin/widgets.dll",
"cwd": "${workspaceFolder}/src"
}
]
}
And now I see a Green play button with the name "FunctionApp" in my "Run and Debug" bar across the top, but when I try to run it, I get an error that says:
Executing task: C:\Program Files\dotnet\dotnet.exe clean /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary <
Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET Copyright
(C) Microsoft Corporation. All rights reserved.
MSBUILD : error MSB1003: Specify a project or solution file. The
current working directory does not contain a project or solution file.
The terminal process "C:\Program Files\dotnet\dotnet.exe 'clean',
'/property:GenerateFullPaths=true',
'/consoleloggerparameters:NoSummary'" terminated with exit code: 1.
Terminal will be reused by tasks, press any key to close it.
EDIT 1
I tried to follow this example:
https://i.stack.imgur.com/a7ZVk.png
I also changed all references in my task.json from "process" to "shell" based on this post: Debugging Azure Function with vscode
So presently, this is what the two files look like:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to .NET Functions",
"type": "coreclr",
"request": "attach",
"processId": "${command:azureFunctions.pickProcess}"
}
]
}
tasks.json
Just showing what I understand is the relevant section...
{
"version": "2.0.0",
"tasks": [
{
"label": "host function",
"command": "func host start",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/src"
}
},
But the error I'm getting is this:
Failed to detect running Functions host within "60" seconds. You may
want to adjust the "azureFunctions.pickProcessTimeout" setting.
When I try Run -> Start with debugging, the application starts, and I can trigger my API... but it doesn't stop at any of the breakpoints.
So the complete solution was to
a) Revert my launch.json back to the original version which looks like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to .NET Functions",
"type": "coreclr",
"request": "attach",
"processId": "${command:azureFunctions.pickProcess}"
}
]
}
b) added new section to my tasks.json:
{
"label": "host function",
"command": "func host start",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/src"
}
},
c) Then I changed ALL references to "process" to "shell" in the tasks.json.
d) Lastly, to fix the error with azureFunctions.pickProcessTimeout, I did the following:
File -> Preferences -> Settings -> search for the specific setting and increased from 60 seconds to 180

VSCode launch configuration to run python file without debugging

I understand that by creating a launch.json file in VSCode (slightly more cumbersome than pycharm), I can set debug configurations to launch individual python files.
For example:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Poker",
"type": "python",
"request": "launch",
"cwd": "C:/Users/dickr/git/poker",
"program": "C:/Users/dickr/git/Poker/poker/main.py",
"console": "integratedTerminal",
"env": {"PYTHONPATH": "${workspaceFolder}${pathSeparator}${env:PYTHONPATH}"}
},
]
}
That all works great, but how can I run it in normal mode, without a debugger? How can this be defined in the launch configuration so I can select this in the dropdown, and potentially pass arguments with it?
Write a task in a tasks.json file. For documentation on tasks, see https://code.visualstudio.com/docs/editor/tasks#_custom-tasks.
Your might look something like this:
{
"version": "2.0.0",
"tasks": [
{
"label": "run python script",
"type": "process",
"command": "python3 C:/Users/dickr/git/Poker/poker/main.py",
"options": {
"cwd": "C:/Users/dickr/git/poker"
},
"presentation": {
"reveal": "always",
}
}
]
}
though I'd suggest that if possible, you use variable substitution to try to get rid of the absolute paths that won't be the same on other machines (assuming you want to be able to run the task on other machines).
Then run the task. You can even bind the task to keyboard shortcuts. See the documentation for more info: https://code.visualstudio.com/docs/editor/tasks.

How to debug Ember addon with breakpoints in VS Code

Am trying to get breakpoints to work in VS Code with an Ember addon (version 3.18). Have tried launch.json as:
{
"version": "0.2.0",
"configurations": [
{
"type": "edge",
"request": "launch",
"name": "Launch Edge against localhost",
"port": 9222,
"runtimeArgs": [ "--remote-debugging-port=9222" ],
"url": "http://localhost:4200",
"sourceMapPathOverrides": {
"dummy/*": "${workspaceFolder}/tests/dummy/app/*",
"test-addon/*": "${workspaceFolder}/addon/*",
}
}
]}
It works fine for setting breakpoints in files in the dummy test app. But when setting a breakpoint in files within the addon folder, VSCode says "Breakpoint set but not yet bound". How can this be fixed? I assume the 2nd sourcemap path override is wrong?
After a bit of further experimenting, seems the 2nd path should be:
"addon-tree-output/test-addon/*": "${workspaceFolder}/addon/*"
Update:
Turns out this still doesn't break inside addon files correctly. eg. in an addon component file:
#action
click() {
console.log('hello') // Set breakpoint here
}
// Instead, jumps to here
Some difference between the dummy and vendor source maps perhaps? There is an option in ember-cli-build.js:
babel: {
sourceMaps: 'inline'
}
but this only applies to the dummy test app as it states in the comment underneath it?

Debug FastAPI application in VSCode

i'm trying to debug an application (a web api) that use FastAPI (uvicorn)
I'm also using poetry and set the projev virtual environment in vscode.
i read this tutorial to setup uvicorn and this one to setup vscode but i think i'm doing something wrong in set it up.
I tried to setup the launch.json both as python: module and python: current file
The problem seems that it doesn't recognize the project structure cause when i run the debug it stopped in an import statement with this error:
Exception has occurred: ImportError
attempted relative import with no known parent package
This is my current launch.json configuration:
"configurations": [
{
"name": "Python: local debug",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/src/topic_service/service/__init__.py",
"args" : ["--port", "8000"]
},
]
I also tried to add a .env file setting PYTHONPATH:
PYTHONPATH=.:${PYTHONPATH}
Locally i run the application as follow:
poetry run uvicorn src.main:app --port 8080 --reload
Does anyone know how to correctly setup vscode to debug an uvicorn application?
Thank you
UPDATE:
I also tried what this article says. the debugger seems to start but nothing happen (no breakpoint is triggered)
Try this configuration.
{
"name": "Python: Module",
"type": "python",
"request": "launch",
"module": "uvicorn",
"args": ["src.main:app","--reload"]
}
Likewise you provide uvicorn module with necessary args during development of FastAPI application, you need to configure your launch.json located in .vscode directory with respective values.
I did a write up for custom project configurations to debug FastAPI in VS Code here
Suppose you issue the following command to run FastAPI on uvicorn server with args mentioned as below
uvicorn main:app --reload --port 8000
then your launch.json should have module with value of uvicorn and each of the args separated by space as items of the args array.
"module": "uvicorn",
"type": "python",
"request": "launch",
"args": [
"main:app",
"--reload",
"--port",
"8000"
],
"env": {
"usersecret": "some$Ecret",
}
You can have this launch.json file in .vscode and then modify the args array in the JSON configuration as per your project structure.
{
// 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": "Python: FastAPI",
"type": "python",
"request": "launch",
"module": "uvicorn",
"env": {
"db_username": "postgres",
"db_password": "secret",
"host_server": "localhost",
"database_name": "fastapi",
"ssl_mode": "prefer",
"db_server_port": "5432"
},
"args": [
"main:app",
"--reload",
"--port",
"8000"
]
}
]
}
For me worked with this configurations:
On Debug section on VSCode, choose create launch.json option. Probally it will open launch.json on .vscode folder in your root folder explorer
like this, inside of launch.json put this:
"version": "0.2.0",
"configurations": [
{
"name": "Python: FastAPI",
"type": "python",
"request": "launch",
"module": "uvicorn",
"cwd": "${workspaceFolder}/<folder to your main.py>",
"args": [
"main:app",
"--reload",
"--port", //these arg are optional
"3003"
]
}
]
}
Now , just run your debugger and have a nice day!
Edit: The cwd ensure that your debbuger will find the right path to your main.py file. So, for whos use multiple debuggers or uses outside vsCode with launch.json it's a nice choice use it.
The quick and easy way: launch debugger F5 and then select FastAPI Debug Configuration:
(p.s. this works on the VSCode Insiders; haven't tried it on a regular version)
The way i debug is quite basic, hope it helps
i have .py file with this config:
import uvicorn
from app.main import api
if __name__ == "__main__":
dev = 1
if dev==0:
#use this one
uvicorn.run(api, host="127.0.0.1", port=5000, log_level="info")
if dev == 1:
#or this one
uvicorn.run('app.main:api', host="127.0.0.1", port=5000, log_level="info", reload=True, debug=True)
if dev == 2:
uvicorn.run('app.main:api', host="127.0.0.1", port=5000, log_level="info", workers=2)
and run the file with the vscode debugger, the important thing is to run the app with the debug flag because otherwise the debugger skips the breakpoints (at least in my case)

How to start both Angular app and WebApi service from VSCode on F5 or Ctrl+F5

I have top-level folder Homepage with the following structure:
--Homepage
----Client <- Angular app, created with `ng new` command
----Server <- .NET Core WebApi, created with `dotnet new webapi` command
I open VSCode at Homepage level:
I have these extensions installed:
Question
If I want to use single VSCode environment to work on both projects, Client and Server, is it possible to bind F5 (or Ctrl+F5) to start both projects together?
Client app I start using ng serve (it will run on http port 4200)
Server app I start using dotnet run (it will run on https port 5001)
I have just one common .vscode folder on Homepage (root level):
By default, when first created, the content of launch.json was this:
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/Server/bin/Debug/netcoreapp2.1/Server.dll",
"args": [],
"cwd": "${workspaceFolder}/Server",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
,]
}
So, when I press F5 it builds and start the Server app, the page opens at https://localhost:5001, from there I can navigate to https://localhost:5001/api/values and see WebApi works.
But the Client app doesn't start at all.
So, I thought if I add Debugger for Chrome extension's settings to launch.json, it should work, so I clicked on Add Configuration and added corresponding section:
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}"
},
I changed port from 8080 to 4200, since ng serve hosts on port 4200
But it does not start the Client app.
Please advice. Thanks
I have similar (node.js for API) and spent quite some times couldn't resolved, for example use && or &. Result is either API up or Angular up, never the both.
Anyway I finally realized have both Api and UI in the same folder/project/solution is not practical. An API is not specific to an UI, it's a universal DLL/service, should be siting somewhere by itself. So I separated them into two diff folders and have 2 VSC instances to run them:
start the API in debug mode
in 2nd VSC, run ng serve and let it take time to build
when ng says "Compiled successfully" go to launch.json to start the debug entry associated with Chrome
they work perfectly.