I'm running tests using Spectron, mocha and chai-as-promised. My IDE is Visual Studio Code.
I start the app from within the tests as follows:
this.app = new Application({
path: electron,
args: ['.']
});
// Then at some point I run this.app.start()
Can I connect the Visual Studio Code debugger to this application? I can run debug my test code but I need to debug the app at some point.
Yes you can debug your tests with VsCode.
For enable to debug, you should add specific configurations to launch.json like below to .
{
"name": "Debug Test Process",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"args": [
"--timeout",
"999999",
"--colors",
]
}
Related
Trying to debug a minitest test on a non-rails ruby application and I have the following config in the launch.json file:
{
"name": "Debug a rake task",
"type": "Ruby",
"request": "launch",
"useBundler": true,
"cwd": "${workspaceRoot}",
"showDebuggerOutput": true,
"pathToBundler": "/home/user/.rbenv/versions/2.5.5/bin/bundle",
"pathToRDebugIDE": "/home/user/.rbenv/versions/2.5.5/bin/rdebug-ide",
"program": "/home/user/.rbenv/versions/2.5.5/bin/rake",
"args": [
"test",
],
"env": {
"LOG_LEVEL": "debug",
"TEST": "test_file.rb",
"TESTOPTS": "--name=test_name",
}
},
Even though the breakpoints of the Rakefile are hit, neither the breakpoints of test_file.rb nor the breakpoints within the app are hit.
I suspect this might be because rake task are called as separate processes but I couldn't figure out how to handle this case. How can I make the debugger stop at the breakpoints of the app and the test files?
PS: I use byebug at the moment; however, it doesn't replace a IDE based debugger.
I have to be able to debug cucumber features. I used the solution from here
How to debug Cucumber in Visual Studio Code (VSCode)?
I have launch.json in Visual Studio Code
{
"type": "node",
"request": "launch",
"name": "Via NPM",
"runtimeExecutable": "npm",
"windows": {
"runtimeExecutable": "npm.cmd"
},
"env":{
"NODE_PATH": "/usr/local/bin/"
},
"runtimeArgs": [
"run",
"debug"
],
"port": 5858
}
I have a script in package.json
"debug": "node --inspect-brk=5858 ./node_modules/.bin/cucumber-js -r #babel/register -r #babel/polyfill -t '#ui'"
and when I run debug from VS code, and connect to the debugger from Chrome.
Chrome debugs cucumber-js instead of my features:
I don't want to debug cucumber scripts, I want debug my features.
What did I do wrong?
If you debug next, you will debug your code
I have an Angular 2+ project with Protractor UI tests with a layer of CucumberJS over it, thus I can define steps in Gherkin.
In Visual Studio Code I have defined launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/protractor/bin/protractor",
"stopOnEntry": false,
"args": [
"${workspaceRoot}/protractor.conf.js"
],
"outFiles": [
"./dist/out-tsc"
]
}
],
"compounds": []
}
When I press F5 all the tests are executed and they all success, however no breakpoint is hit. On the other hand there is no problem with hitting breakpoints in WebStorm, I just point to the protractor.conf and it works.
Question: What more should I declare in launch.json to enable hitting the breakpoints in Visual Studio Code?
I am trying to use Visual Studio Code to Debug a MSTest unit test project. But the tests just run and the breakpoint is never reached.
Here is my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Test (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "C:\\Program Files\\dotnet\\dotnet.exe",
"args": ["test"],
"cwd": "${workspaceRoot}",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
How can I debug a unit test (MSTest)? This same problem exists for XUnit.
If you are using the latest version of VS Code (I'm using v1.29.0), debugging unit test is in-built feature.
You need to first build the solution dotnet build for the test run & debug options to appear.
Try https://github.com/Microsoft/vstest-docs/blob/master/docs/diagnose.md#debug-test-platform-components (assumes you're using dotnet-cli tools 1.0.0)
> set VSTEST_HOST_DEBUG=1
> dotnet test
# Process will wait for attach
# Set breakpoint in vscode
# Use the NETCore attach config from vscode and pick the dotnet process
Try and reload VS Code, worked for me.
Press Ctrl+Shift+P which opens the command palette and then :
Reload Window
Before building, remember to include in your .csproj file
<GenerateProgramFile>false</GenerateProgramFile>
or else it will not know what to run...
Program.cs(160,21): error CS0017: Program has more than one entry point defined. Compile with /main to specify the type that contains the entry point. [/Users/.../Fraction.csproj]
I'm trying to debug jasmine test cases in visual studio code debug console.
Below is my launch.json and gulpfile.js configuration :
In my gulp task I tried using 'gulp-jasmine' to run test cases and "gulp-karma" (commented below jasmine) alternatively. Now using either one I can successfully excute my test cases through command line (gulp "task name") or through task.json file in vs code.
However, I want to debug my jasmine test cases(spec/StockSpec.js ) itself. On running debug (f5), the debugger successfully pauses on entry point in gulpfile.js as below :
From here on I'm not able to navigate to my jasmine test cases no matter which scenario I choose:
Scenario 1: On clicking Step Over (F10) --it skips to next gulp task
Scenario 2: On clicking Step In/out (F11 / shift +F11) --it jumps to some internal module.js , index.js etc files.
How should I proceed further?
This runs through gulpfile.js, but doesn't trigger a gulp task itself. The startup program needs to be gulp.js with the gulp task as argument. You can then simply set a breakpoint in your unit test.
The following launch configuration works for me to trigger the unittests gulp task:
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/gulp/bin/gulp.js",
"stopOnEntry": false,
"args": [
"unittests"
],
"cwd": "${workspaceRoot}/src/",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": false,
"outDir": null
}