- Open the debug tab
- Add a Chrome configuration, it'll fill out most the fields for you. For the port change it to
9876(or whatever is specified in yourkarma.conf.js). See below. - Set breakpoint(s) in the code you want to debug
- Run your the debug task which will open a chrome window to the specified port
- Run your test command (
ng test) and refresh the opened Chrome window if necessary
Sample configuration, they are created in a filed called 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": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:9876",
"webRoot": "${workspaceFolder}"
}
]
}
Answer from MkMan on Stack Overflownode.js - Debug jasmine tests written in typescript node in vs code - Stack Overflow
How to debug Jasmine tests run from Grunt in Visual Studio Code?
debugging - How to debug Unit Tests with Karma/Jasmine in Visual Studio Code? - Stack Overflow
typescript - How to run jasmine tests in visual studio code? - Stack Overflow
Videos
In new jasmine-ts version, you have to include the jasmine.json to the args as this:
{
"type": "node",
"request": "launch",
"name": "Jasmine Current File",
"program": "${workspaceFolder}/node_modules/jasmine-ts/lib/index",
"args": ["--config=jasmine.json", "${file}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
To avoid this issue:
No specs found Finished in 0.003 seconds Incomplete: No specs found Randomized with seed 60766 (jasmine --random=true --seed=60766)
Below configuration will debug current test file - please open the required test file in VS Code and start debugging with this configuration:
{
"type": "node",
"request": "launch",
"name": "Jasmine Current File",
"program": "${workspaceFolder}/node_modules/jasmine-ts/lib/index",
"args": ["${file}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
I don't think you can currently do something like node --debug-brk grunt test where test will spin up jasmine tests - since jasmine will invoke node on these spec files without the debug flag in place. I tried this and here is what I got:
node --debug-brk=3691 --nolazy ../../../usr/local/bin/grunt kftest --schema=9.2.1 --dbtype=sqlite --target=builder/properties --spec=test/builder/properties/properties-spec.js
Debugger listening on port 3691
Running "kftest" task
>> going to run with spec: test/builder/properties/properties-spec.js
>> command: node --debug-brk=46307 /Users/computername/project/node_modules/jasmine-node/lib/jasmine-node/cli.js test/builder/properties/properties-spec.js
Running "shell:kftest" (shell) task
Debugger listening on port 46307
This isn't too helpful since now vscode's debugger will be looking at 3691 while 46307 is not being inspected by anything - and I don't know how to tell vscode to also listen to that port.
Soooo what I ended up doing was to follow the answer posted here: Debugging jasmine-node tests with node-inspector
Basically my vscode launch.json included a config that looked like this:
{
"name": "Jasmine-Node Debugging",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/node_modules/jasmine-node/lib/jasmine-node/cli.js",
"request": "launch",
"type": "node",
"args": [
"test/builder/properties/properties-spec.js"
]
}
Hope that helps.
This launch config works for me in VS Code 0.10.2:
{
"name": "grunt",
"type": "node",
"request": "launch",
"program": "/usr/local/bin/grunt",
"args": ["test"],
"stopOnEntry": false
}
Setting a breakpoint in my "test" task made the VS Code debugger to stop there. I had to install grunt locally (in the folder where I have the Gruntfile).
The following configuration works fine for me and allow to debug jasmine tests. In your launch.json:
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Launch Unit Tests",
// Type of configuration.
"type": "node",
// Workspace relative or absolute path to the program.
"program": "spec/runner.ts",
// Automatically stop program after launch.
"stopOnEntry": false,
// Command line arguments passed to the program.
"args": [],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": null,
// Optional arguments passed to the runtime executable.
"runtimeArgs": ["--nolazy"],
// Environment variables passed to the program.
"env": {
"NODE_ENV": "development"
},
// Use JavaScript source maps (if they exist).
"sourceMaps": true,
// If JavaScript source maps are enabled, the generated code is expected in this directory.
"outDir": "dist/spec",
"request": "launch"
}
The runner.ts is as follows:
'use strict';
var Jasmine = require('jasmine');
var j = new Jasmine();
j.loadConfigFile('spec/support/jasmine.json');
j.configureDefaultReporter({
showColors: true
});
j.execute();
The project file structure is:
-spec
--runner.ts
--support
----jasmine.json
--folderWithTests1
-dist
--spec
.....
Note - "dist" is the folder where spec ts files are built to. Therefore "outDir" is set to "dist/spec".
Hope this will help.
I've updated VS Code to 0.10.9 and Typescript to 1.8.2 and this now "just works".