多个HTML记者Karma Test Runner

时间:2015-12-16 05:17:26

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

我正在使用带有Jasmine框架的Karma Test runner。我想用下面的记者。但我无法将两者结合使用,有人可以帮我解决这个问题吗?

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
  });
};

1 个答案:

答案 0 :(得分:1)

TLDR:我提交了拉取请求,但不确定何时会查看。目前,请卸载当前版本的npm install Nocomm/karma-jasmine-html-reporter --save-dev并运行reporters: ['kjhtml', 'html']

使用方式:karma-jasmine-html-reporter\src\index.js

<强> --------------------------------------- < / p>

你确定可以,我将提交拉取请求,以便两者不会发生冲突。现在,您可以编辑module.exports = { 'reporter:kjhtml': ['type', initReporter] }; 文件的最后一行。

'reporter:html'

只需将'reporter:kjhtml'更改为{{1}},然后在您的业力配置文件中反映您在哪里定义记者。他们俩现在应该并肩工作。