-
-
Save paambaati/54d33e409b4f7cf059cc to your computer and use it in GitHub Desktop.
{ | |
"version": "0.1.0", | |
// List of configurations. Add new configurations or edit existing ones. | |
// ONLY "node" and "mono" are supported, change "type" to switch. | |
"configurations": [ | |
{ | |
// Name of configuration; appears in the launch configuration drop down menu. | |
"name": "Run app.js", | |
// Type of configuration. Possible values: "node", "mono". | |
"type": "node", | |
// Workspace relative or absolute path to the program. | |
"program": "app.js", | |
// 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, | |
// Environment variables passed to the program. | |
"env": { "NODE_ENV": "production"} | |
}, | |
{ | |
// Name of configuration; appears in the launch configuration drop down menu. | |
"name": "Run mocha", | |
// Type of configuration. Possible values: "node", "mono". | |
"type": "node", | |
// Workspace relative or absolute path to the program. | |
"program": "/Users/gp/Projects/evol_dealermgmt/node_modules/mocha/bin/_mocha", | |
// Automatically stop program after launch. | |
"stopOnEntry": false, | |
// Command line arguments passed to the program. | |
"args": ["test/unit.js"], | |
// 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, | |
// Environment variables passed to the program. | |
"env": { "NODE_ENV": "production"} | |
} | |
] | |
} |
@cameronwp that should be sent as PR to this repo.
Since once you google "run mocha on VS code" this page is coming in first place.
For TypeScript make sure that the launch config enables source maps if you want to use breakpoints.
{
"name": "Run mocha",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"stopOnEntry": false,
"sourceMaps": true,
"args": ["test/**/*.js", "--no-timeouts"],
"cwd": "${workspaceRoot}",
"runtimeExecutable": null,
"env": { "NODE_ENV": "testing"}
}
To run only the file you have currently open (the active tab). Very convenient workflow:
- open file
- set breakpoint
- hit F5
{
"name": "Run mocha",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"stopOnEntry": false,
"args": ["${file}", "--no-timeouts"],
"cwd": "${workspaceRoot}",
"runtimeExecutable": null,
"env": { "NODE_ENV": "testing"}
}
thanks! it works 👍
Thanks @akobler, your solution is great
FYI on Win10 (VSC 1.18, node 6.9.4 my current working Debugging config:
{
"name": "Run mocha",
"type": "node",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": ["${workspaceFolder}/test/**/*.spec.js"],
"request": "launch",
"outFiles": [
"${workspaceFolder}/**/*.js"
]
}
I tried many variations of the things in this thread and wasn't able to get the breakpoints to correspond to the correct lines. Finally I was able to get it working by adding "retainLines": true
to my .babelrc
file.
I tried many variations of the things in this thread and wasn't able to get the breakpoints to correspond to the correct lines. Finally I was able to get it working by adding "retainLines": true to my .babelrc file.
@kenjiO Better, for me, but still no cigar. :-( Some breakpoints are still on the wrong line...
@M3ssman Thanks, works perfectly well
It's working for me in Win10 (VSCode version 1.20.1).
Using the gui interface:
1-debug tap
2-add new configuration
3-mocha tests
this is my launch.json file
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/test",
"test/**/*.js"
],
"internalConsoleOptions": "openOnSessionStart"
},
{
"type": "node",
"request": "launch",
"name": "Iniciar programa",
"program": "${workspaceFolder}\\bin\\www"
}
]
}
@kenjiO Thanks very much! That was the piece I needed.
For ES6 this configuration worked for me reference
{
"name": "Run ES6 Tests",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"args": [
"./test/*.js",
"--require", "babel-register",
"-u", "tdd",
"--timeout", "999999",
"--colors"
],
"runtimeArgs": [
"--nolazy"
],
"sourceMaps": true
},
For mocha 8 and VS Code 1.27.2 on OSX this worked for me (needed to specify ports)
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Iniciar prueba actual",
"program": "[..path to mocha 8]/v8.11.1/bin/mocha",
"args": ["${file}", "--no-timeouts","--inspect-brk=9229"],
"port": 9229
}
]
}
Moreover, take into account that this launches the actual opened file... not a specific one. Modify ${file} to match your tests path if you want to.
"args": ["${file}", "--no-timeouts","--inspect-brk=9229"],
@fruscitti i got this working by passing the args through like this:
"args": ["--compilers", "js:babel-core/register", "--require", "./test/test_helper.js"],
Simple and works perfect, thanks. Only to say that --compilers is now deprecated and you have to use --required instead (Mocha warn you about that).
Does anyone know how to configure this to debug when executing tests via a test script? Setup is:
- "test" config in package.json of project specifying the mocha command to execute
- 'npm test' command used in internal terminal of vscode with '-g' param to allow for execution of specific descriptions within coffescript files
I want to be able to debug the execution of these individual tests(i.e. run 'npm test -- -g ' in vscode and break when it reaches a bp). Is this possible? Would an 'attach' config be needed instead of 'launch'? I've tried the standard debug configs provided in vscode, and tried to modify them based on info found in various places, but no success so far. Any help would be great.
i love you <3 thanks
Is there some way to make VS Code interpret a failed test as a breakpoint so one can quickly see more details about what went wrong?
I'm already using the --bail
mocha argument, but that just makes the debugger finish after a test fails.
not working for me, I get : ReferenceError: describe is not defined using the config above.
Didn't work for me - if I add the =xxxx (port number) after --inspect-brk, then I get SyntaxError: .../.vscode/launch.json: Unexpected token / in JSON at position 6.
If I don't add it, it tries port 9229, which is not available, regardless of the separate port: xxxx in the json configuration.
FYI on Win10 (VSC 1.18, node 6.9.4 my current working Debugging config:
{ "name": "Run mocha", "type": "node", "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", "args": ["${workspaceFolder}/test/**/*.spec.js"], "request": "launch", "outFiles": [ "${workspaceFolder}/**/*.js" ] }
Thank you! 😄
@M3ssman:
It's working for me in Win10 (VSCode version 1.8.1) using the configuration that @cameronwp posted above: