如果使用节点,则很容易调试:
//.vscode/launch.json
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
...
但是,如果我正在使用摩卡测试,该如何调试呢?
我尝试使用:
"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);
});
使用单元测试选项运行调试器
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句