如何使用 visual studio 代码调试 javascript 中的 mocha 测试?
How to debug with visual studio code a mocha test in javascript?
如果你用的是node,调试起来很方便:
//.vscode/launch.json
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
...
但是如果我使用的是 mocha 测试,我该如何调试呢?
我试过使用:
"configurations": [
{
"name": "Launch",
"type": "mocha",
"request": "launch",
但是无效。有人知道吗?
在 .vscode/launch 中创建这个新的调试目标。json
{
"name": "Unit tests",
"type": "node",
"program": "${workspaceRoot}/mocha.js",
"stopOnEntry": true,
"args": ["${workspaceRoot}/TESTTODEBUG.js"],
"runtimeExecutable": null,
"env": {
"NODE_ENV": "test"
}
创建文件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);
});
运行 带有单元测试选项的调试器
如果你用的是node,调试起来很方便:
//.vscode/launch.json
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
...
但是如果我使用的是 mocha 测试,我该如何调试呢?
我试过使用:
"configurations": [
{
"name": "Launch",
"type": "mocha",
"request": "launch",
但是无效。有人知道吗?
在 .vscode/launch 中创建这个新的调试目标。json
{ "name": "Unit tests", "type": "node", "program": "${workspaceRoot}/mocha.js", "stopOnEntry": true, "args": ["${workspaceRoot}/TESTTODEBUG.js"], "runtimeExecutable": null, "env": { "NODE_ENV": "test" }
创建文件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); });
运行 带有单元测试选项的调试器