【问题标题】:Multiple HTML Reporters Karma Test Runner多个 HTML 记者 Karma 测试运行器
【发布时间】:2016-03-22 03:22:20
【问题描述】:

我正在使用带有 Jasmine 框架的 Karma 测试运行器。我正在尝试使用以下记者。但是我不能同时使用,有人可以帮我吗?

Karma-html-reporter 帮助生成测试用例的 HTML 报告,而 karma-jasmine 在浏览器中美化测试用例。

我认为问题在于一些命名,至于这两个,

reporters: ["html"]

被使用...有人可以提出一些方法来使它们都起作用。

这是我的 Karma.conf.js

module.exports = function (config) {

  config.set({
    // base path that will be used to resolve all patterns (eg. files, exclude)
    "basePath": ".",

    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    "frameworks": ["jasmine", "sinon"],

    // list of files / patterns to load in the browser
    "files": ["dest/assets/test/myfile.debug.js", "test/**/help*.js",
              "test/**/test*.js"],

    // list of files to exclude
    "exclude": [],

    // Reporters to use
    "reporters": ["nyan", "html"],

    // Configurations for Coverage Reporter
    "coverageReporter": {
      "dir": "coverage/",
      "reporters": [
        {"type": "html", "subdir": "CoverageReportHTML"},
        {"type": "text", "subdir": ".", "file": "coverage.txt"}
      ]
    },

    // Configurations for HTML Reporter
    "htmlReporter": {
      "outputDir": "karma_html", // where to put the reports
      "templatePath": null, // set if you moved jasmine_template.html
      "focusOnFailures": true, // reports show failures on start
      "namedFiles": false, // name files instead of creating sub-directories
      "pageTitle": null, // page title for reports; browser info by default
      "urlFriendlyName": false, // simply replaces spaces with _ for files/dirs
      "reportName": "report-summary" // report summary filename; browser info by default
    },

    // Karma Webserver port
    "port": 9999,

    // enable / disable colors in the output (reporters and logs)
    "colors": true,

    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    "logLevel": config.LOG_ERROR,

    // enable / disable watching file and executing tests whenever any file changes
    "autoWatch": true,

    // Custom Launchers / Browsers Configurations
    "customLaunchers": {
      "IE10": {"base": "IE", "x-ua-compatible": "IE=EmulateIE10"},
      "IE9": {"base": "IE", "x-ua-compatible": "IE=EmulateIE9"},
      "IE8": {"base": "IE", "x-ua-compatible": "IE=EmulateIE8"},
      "IE7": {"base": "IE", "x-ua-compatible": "IE=EmulateIE7"}
    },

    // Browsers to Launch - Available launchers: https://npmjs.org/browse/keyword/karma-launcher
    "browsers": ["Chrome", "Firefox"],
    // browsers: ["Chrome", "Safari", "IE", "Firefox", "IE8","IE9", "IE10"],
    // if true, Karma captures browsers, runs the tests and exits (Keep false for CI)
    "singleRun": true
  });
};

【问题讨论】:

    标签: javascript unit-testing karma-runner karma-jasmine


    【解决方案1】:

    TLDR:我提交了一个拉取请求,但不确定它何时会被查看。现在,卸载当前版本的karma-jasmine-html-reporter 并运行npm install Nocomm/karma-jasmine-html-reporter --save-dev

    这样使用:reporters: ['kjhtml', 'html']

    ---------------------------------------

    你当然可以,我将提交一个拉取请求,这样两者就不会发生冲突。现在您可以编辑karma-jasmine-html-reporter\src\index.js 文件的最后一行。

    module.exports = {
      'reporter:kjhtml': ['type', initReporter]
    };
    

    只需将 'reporter:html' 更改为 'reporter:kjhtml',然后反映您在 karma 配置文件中定义记者的位置。它们现在应该可以并排工作了。

    【讨论】:

    • 谢谢...几天前我想通了。但是服务器上的代码会自动更新包,因此会覆盖我的本地更改。 希望这个拉取请求尽快合并
    • 是的......不幸的是,karma-jasmine-html-reporter 的作者最近似乎没有更新项目。所以我将使用我为所有其他项目制作的叉子:npm install Nocomm/karma-jasmine-html-reporter。我的 fork 还更新了文档(最少)以反映更改。
    猜你喜欢
    • 2020-08-26
    • 2019-02-17
    • 1970-01-01
    • 1970-01-01
    • 2014-12-20
    • 2013-08-24
    • 1970-01-01
    • 1970-01-01
    • 2014-01-04
    相关资源
    最近更新 更多