Reputation: 2472
If you are using node, it is easy to debug:
//.vscode/launch.json
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
...
But if I am using mocha tests, how can I debug it?
I have tried to use:
"configurations": [
{
"name": "Launch",
"type": "mocha",
"request": "launch",
But it is not valid. Does anyone have any idea?
Upvotes: 1
Views: 2051
Reputation: 2472
Create this new debug target in .vscode/launch.json
{
"name": "Unit tests",
"type": "node",
"program": "${workspaceRoot}/mocha.js",
"stopOnEntry": true,
"args": ["${workspaceRoot}/TESTTODEBUG.js"],
"runtimeExecutable": null,
"env": {
"NODE_ENV": "test"
}
Create the file mocha.js
'use strict';
// Dependencies
var Mocha = require('mocha');
// Determine which tests to run based on argument passed to runner
var args = process.argv.splice(2);
//var args = ["./tests/unit/services/supra-statement.service.test.js"];
var files;
//Define Mocha
var mocha = new Mocha({
timeout: 60000,
reporter: 'spec',
globals: ['Associations', 'CREATE_TEST_WATERLINE', 'DELETE_TEST_WATERLINE']
});
args.forEach(mocha.addFile.bind(mocha));
//Run unit tests
mocha.run(function (failures) {
process.exit(failures);
});
Run the debugger with the Unit test Option
Upvotes: 4