use*_*479 4 node.js jasmine typescript visual-studio-code
我的单元测试是用 jasmine 写的,而那些是打字稿
// 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"
Run Code Online (Sandbox Code Playgroud)
我已经使用此配置在 vscode 中调试 .spec.ts 文件,但它没有启动调试器,而是运行所有测试并开始调试。
我在 about.service.spec.ts 的测试用例之一中放置了一个断点,但没有触发断点。任何人都可以帮助我为 jasmine 测试设置 vscode 调试吗?
在新的 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"
}
Run Code Online (Sandbox Code Playgroud)
为了避免这个问题:
未找到规格 0.003 秒内完成 不完整:未找到规格 随机种子 60766 (jasmine --random=true --seed=60766)
下面的配置将调试当前的测试文件 - 请在 VS Code 中打开所需的测试文件并使用此配置开始调试:
{
"type": "node",
"request": "launch",
"name": "Jasmine Current File",
"program": "${workspaceFolder}/node_modules/jasmine-ts/lib/index",
"args": ["${file}"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
}
Run Code Online (Sandbox Code Playgroud)