我已经使用 VS code 来调试我的 Angular jasmine karma 测试有一段时间了,但我总是遇到一个问题,在调试测试几次后,断点停止工作。我必须重新启动 VS code 才能使它们再次工作,而且情况似乎变得更糟,即在一次调试后停止工作!
仅供参考,调试工作正常,直到停止。断点停止工作后,它们仍然显示为附加状态(即显示为红色)并且测试运行正确。
我安装了 Karma Test Explorer(适用于 Angular、Jasmine 和 Mocha):
https://marketplace.visualstudio.com/items?itemName=lucono.karma-test-explorer
我启用了“测试资源管理器:使用本机测试”(但在没有本机测试的情况下也会出现问题)。
我不使用 launch.json 来附加。
n.b.我经常收到通知/错误,指出测试操作进入此状态时仍在进行中/活动,重新启动是我知道如何重置此状态的唯一方法!
我的 karma 文件配置如下:
module.exports = function (config) {
config.set({
basePath: "",
frameworks: ["jasmine", "@angular-devkit/build-angular"],
plugins: [
require("karma-coverage"),
require("karma-jasmine"),
require("karma-chrome-launcher"),
require("karma-jasmine-html-reporter"),
require("karma-coverage-istanbul-reporter"),
require("@angular-devkit/build-angular/plugins/karma"),
require("karma-spec-reporter"),
require("karma-junit-reporter"),
],
client: {
clearContext: false, // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require("path").join(__dirname, "./coverage"),
reports: ["html", "lcovonly", "text-summary", "cobertura"],
fixWebpackSourcePaths: true,
},
// reporters: config.angularCli && config.angularCli.codeCoverage ? ['dots', 'coverage-istanbul'] : ['dots', 'kjhtml'],
reporters:
config.angularCli && config.angularCli.codeCoverage
? ["dots", "coverage-istanbul", "junit"]
: ["dots", "kjhtml", "junit"],
specReporter: {
maxLogLines: 5, // limit number of lines logged per test
suppressErrorSummary: true, // do not print error summary
suppressFailed: false, // do not print information about failed tests
suppressPassed: false, // do not print information about passed tests
suppressSkipped: true, // do not print information about skipped tests
showSpecTiming: false, // print the time elapsed for each spec
},
mime: {
"text/x-typescript": ["ts", "tsx"],
},
port: 9876,
colors: true,
logLevel: config.LOG_ERROR,
autoWatch: true,
singleRun: false,
files: [
{
pattern: "src/assets/**/*.png",
watched: true,
included: true,
served: true,
nocache: false,
},
],
proxies: {
"/assets/": "/base/src/assets/images/fixtures",
},
restartOnFileChange: true,
browsers: ["ChromeHeadlessNoSandbox"],
customLaunchers: {
ChromeHeadlessNoSandbox: {
base: "ChromeHeadless",
flags: [
"--no-sandbox",
"--user-data-dir=/tmp/chrome-test-profile",
"--disable-web-security",
"--remote-debugging-address=0.0.0.0",
"--remote-debugging-port=9222",
],
debug: true,
},
},
});
};
如有任何帮助,我们将不胜感激。
检查其他 VS Code 扩展是否存在干扰。禁用它们并测试问题是否仍然存在。如果这不起作用,请卸载并重新安装 Karma Test Explorer 扩展(如果是配置问题)。