簡體   English   中英

如何使用 Visual Studio 代碼調試 javascript 中的 mocha 測試?

[英]How to debug with visual studio code a mocha test in javascript?

如果您使用的是節點,則很容易調試:

//.vscode/launch.json
"configurations": [
    {
        "name": "Launch",
        "type": "node",
        "request": "launch",
        ...

但是如果我使用 mocha 測試,我該如何調試呢?

我曾嘗試使用:

"configurations": [
    {
        "name": "Launch",
        "type": "mocha",
        "request": "launch",

但它無效。 有沒有人有任何想法?

  1. 在 .vscode/launch.json 中創建這個新的調試目標

    { "name": "Unit tests", "type": "node", "program": "${workspaceRoot}/mocha.js", "stopOnEntry": true, "args": ["${workspaceRoot}/TESTTODEBUG.js"], "runtimeExecutable": null, "env": { "NODE_ENV": "test" }
  2. 創建文件 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); });
  3. 使用單元測試選項運行調試器

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM