如果你使用的是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); });
使用单元测试选项运行调试器
关于javascript - 如何使用 visual studio 代码调试 javascript 中的 mocha 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36065089/