当 karma-jasmine 给出 `WARN:` 消息时,我如何追踪导致它们的规范文件或组件?

Yas*_*oor 4 karma-runner karma-jasmine angular

我有很多测试会发出警告。

ng 测试输出示例

如果不逐个筛选每个规范,启用和禁用每个规范,就几乎不可能追踪导致每个错误的规范文件。有什么办法可以让我WARN:显示导致它的文件/组件/服务?

Jar*_*xus 5

2021 年 1 月

我一直在寻找一个好的解决方案(例如启用某些选项karma.conf.js)但没有找到任何...

我发现的一种方法是安装这个库karma-spec-reporterhttps://www.npmjs.com/package/karma-spec-reporter)。它向您显示按顺序执行的每个测试。因此,要追踪警告,您只需查看警告消息下方的组件名称。

示例: screen_capture_running_tests.png

在我的示例中,警告与 EditGroupComponent

安装:

npm i karma-spec-reporter

然后将这些行添加到您的karma.conf.js

config.set({
  ...

  plugins: [
    ...
    require('karma-spec-reporter')
  ],

  // With extra options if you want
  specReporter: {
    suppressErrorSummary: false, // 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
    failFast: false              // test would finish with error when a first fail occurs. 
  },

  // And replace 'progress' by 'spec'
  reporters: ['spec'],

  ...
});
Run Code Online (Sandbox Code Playgroud)

如果你不喜欢在你的项目中有另一个依赖。安装它,更正所有并卸载它。