【问题标题】:karma-htmlfile-reporter on karma start not giving html outputkarma 上的 karma-htmlfile-reporter 开始不提供 html 输出
【发布时间】:2017-09-28 19:30:50
【问题描述】:

我正在使用karma angular-cli 使用jasmine 和javascript 运行测试用例。

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

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


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

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

karma start --reporters html

但我得到的不是测试用例结果,而是这些。

编辑: 添加了 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"
}

我得到的结果是 谁能帮助如何在 html 中生成测试用例结果?

【问题讨论】:

  • 你使用什么单元测试框架? (Qunit,Jasmine ??),htmlReporter 应该将测试结果转储到 html 文件中。
  • 我正在使用 jasmine 框架
  • 我认为原因,你没有看到 karma 横幅下的规范,是 karma 可能没有加载 jasmine.css 文件,你可以通过之前的 karma.conf.js 文件加载它其他测试和源文件,在你的 karma-core node_modules 中查找 jasmine.css。
  • 是的,iframe 正在加载。但是在html里面我看不到规格。在节点模块中,我只有业力文件而不是业力核心。即使我尝试了 npm install 我也没有得到任何 karma-core 文件夹。请您尝试探索并为我提供解决方案。

标签: javascript jasmine karma-runner karma-jasmine


【解决方案1】:

使用 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 将产生以下结果:

【讨论】:

  • 对不起,这是不同的插件。我正在使用 karma-html 记者。npmjs.com/package/karma-html-reporter。我仍然尝试了上面的插件,但我还是看不到规范文件。
  • Karma-html-reporter 将输出存储在磁盘中,但 karma-jasmine-html-reporter 将在 karma 上下文页面中显示测试结果。确保您已将 client.clearContext 设置为 false,如上所示,并通过在您的 karma Conf 文件中添加 singleRun:false 来验证您的结果
  • 不,我仍然没有得到。我在给业力开始时遇到错误。 28 09 2017 11:04:50.892:ERROR [plugin]: 找不到插件“karma-phantomjs-launcher”。你忘记安装了吗? npm install karma-phantomjs-launcher --save-dev 28 09 2017 11:04:50.926:ERROR [plugin]: 加载“karma-requirejs”插件时出错:找不到模块'requirejs'
  • 你能分享你的 karma.Conf.js 和 package.json 吗?
  • 我已经添加了这些文件
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-06-16
  • 1970-01-01
  • 2019-12-15
  • 1970-01-01
  • 2017-06-01
  • 2013-07-07
  • 2020-09-03
相关资源
最近更新 更多