javascript - karma 上的 karma-htmlfile-reporter 开始不提供 html 输出

标签 javascript jasmine karma-runner karma-jasmine

我正在使用 karma angular-cli 使用 jasminejavascript 运行测试用例。

在我的 karma.config 文件中,我添加了这些行。

reporters: ['progress','html'],


htmlReporter: {
   outputFile: 'test/units.html'
},

我在命令提示符下运行这个命令

karma start --reporters html

但是我没有得到测试用例结果,而是只得到了这些。

enter image description here

编辑: 添加了 karma.conf.js

// Karma configuration
// Generated on Tue Sep 26 2017 18:46:51 GMT+0530 (India Standard Time)

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'],


    // list of files / patterns to load in the browser
    files: [
      'test-main.js',
      'js/*.js', 
       'test/*.js'
    ],


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


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
    },


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter

    client: {
        clearContext: false
    },
    reporters: ['kjhtml','html'],

    plugins: ['karma-chrome-launcher',
        'karma-firefox-launcher',
        'karma-jasmine',
        'karma-jasmine-html-reporter'],

    // web server port
    port: 9876,


    // 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_INFO,


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


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Chrome'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false,

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity
  })
}

添加了 package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "karma.conf.js",
  "directories": {
    "test": "test"
  },
  "dependencies": {
    "jasmine": "^2.7.0",
    "karma": "^1.7.0",
    "karma-chrome-launcher": "^2.2.0",
    "karma-firefox-launcher": "^1.0.1",
    "karma-ie-launcher": "^1.0.0",
    "karma-jasmine": "^1.1.0",
    "karma-requirejs": "^1.1.0"
  },
  "devDependencies": {
    "jasmine": "^2.8.0",
    "jasmine-core": "^2.8.0",
    "karma": "^1.7.1",
    "karma-chrome-launcher": "^2.2.0",
    "karma-htmlfile-reporter": "~0.3",
    "karma-jasmine": "^1.1.0",
    "karma-jasmine-html-reporter": "^0.1.8",
    "karma-requirejs": "^1.1.0",
    "karma-spec-reporter": "0.0.31"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

我得到的结果是 enter image description here 任何人都可以帮助如何在 html 中生成测试用例结果吗?

最佳答案

使用 karma-jasmine-html-reporter,在 karma 横幅下方打印 jasmine 格式的报告。

karma-jasmine-html-reporter: https://github.com/taras42/karma-jasmine-html-reporter

在您的 karma.conf.js 文件中添加以下内容

module.exports = function(config) {
  config.set({
    client: {
        clearContext: false
    },
    reporters: ['kjhtml'],

    plugins: ['karma-jasmine-html-reporter'] 

  });
};

以上述方式配置 karma 将产生以下结果: enter image description here

关于javascript - karma 上的 karma-htmlfile-reporter 开始不提供 html 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46340997/

相关文章:

node.js - 如何使用 Karma 测试 AngularJS/SocketStream/Node.js 应用程序

javascript - 如何为 ul 列表添加/删除事件类?

angular-cli - 单元测试无法在 VSTS 中运行?

javascript - AngularJS Jasmine 测试 - 元素隔离范围未定义

node.js - 模块未在 karma 中定义

javascript - AngularJS : Reference error of the inject function 中的测试

javascript - 处理来自控制台的nodeJs输入?

c# - C# 中单个按钮有两个操作的弹出消息

javascript - 无论如何,要在 doc.ready 事件之前将 JS 注入(inject) iframe 中?

javascript - 测试 Angular 组件时的 Jasmine spyOn 服务