在vs代码中使用typescript节点编写的调试jasmine测试

问题描述 投票:0回答:2

我用茉莉花编写的单元测试用的是打字稿

// 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文件,但它没有激活调试器,而是运行所有测试并开始调试。

我在一个约.service.spec.ts的测试用例中放了一个断点但没有触发断点。任何人都可以帮我设置茉莉花测试的vscode调试吗?

node.js typescript jasmine visual-studio-code
2个回答
3
投票

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

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

3
投票

在新的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)

© www.soinside.com 2019 - 2024. All rights reserved.