【问题标题】:Debug jasmine tests written in typescript node in vs code在 vs 代码中调试用 typescript 节点编写的 jasmine 测试
【发布时间】:2018-10-16 15:58:57
【问题描述】:

我的单元测试是用 jasmine 编写的,并且在 typescript 中

// about.service.spec.ts
// say 4 to 5 test cases

// spec/support/jasmine.json
{
  "spec_dir": "src/tests/",
  "spec_files": ["**/*.spec.ts"],
  "helpers": ["jasmine-helpers/**/*.ts"],
  ...
}

// launch.json - vscode file
{
  "version": "0.2.0",
  "configurations": [{
      "type": "node",
      "request": "launch",
      "name": "Jasmine tests",
      "preLaunchTask": "debuggertests",
   }]
}

// tasks.json - vscode 
{
 "version": "2.0.0",
 "tasks": [{
    "label": "debuggertests",
    "type": "npm",
    "script": "test:unit",
    "problemMatcher": []
  }]
}

// package.json
// have to use jasmine-ts which is flavor over ts-node
"test:unit": "jasmine-ts JASMINE_CONFIG_PATH=spec/support/jasmine.json"

我已使用此配置在 vscode 中调试 .spec.ts 文件,但它没有触发调试器,而是运行所有测试并开始调试。

我在 about.service.spec.ts 的一个测试用例中设置了一个断点,但没有触发断点。谁能帮我设置 jasmine 测试的 vscode 调试?

【问题讨论】:

    标签: node.js typescript jasmine visual-studio-code


    【解决方案1】:

    在新的 jasmine-ts 版本中,您必须将 jasmine.json 包含到 args 中,如下所示:

    {
      "type": "node",
      "request": "launch",
      "name": "Jasmine Current File",
      "program": "${workspaceFolder}/node_modules/jasmine-ts/lib/index",
      "args": ["--config=jasmine.json", "${file}"],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen"
    }
    

    为了避免这个问题:

    未找到规格 在 0.003 秒内完成 不完整:未找到规格 随机使用种子 60766 (jasmine --random=true --seed=60766)

    【讨论】:

      【解决方案2】:

      以下配置将调试当前测试文件-请在VS Code中打开所需的测试文件并使用此配置开始调试:

      {
            "type": "node",
            "request": "launch",
            "name": "Jasmine Current File",
            "program": "${workspaceFolder}/node_modules/jasmine-ts/lib/index",
            "args": ["${file}"],
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen"
       }
      

      【讨论】:

        猜你喜欢
        • 2018-10-16
        • 1970-01-01
        • 2017-02-11
        • 2015-06-18
        • 2018-10-22
        • 1970-01-01
        • 1970-01-01
        • 2018-10-16
        • 2018-12-15
        相关资源
        最近更新 更多