【问题标题】:How to get Karma html reporter working in karma conf?如何让 Karma html 记者在 karma conf 中工作?
【发布时间】:2015-12-08 09:53:05
【问题描述】:

如何让 Karma html 记者在 karma conf 中工作?

要运行我的单元测试,我输入:“npm run test”,测试在 git bash 中运行良好。 但我想在reporter.html 文件中看到它们。

我在根目录中的 karma conf 文件旁边创建了一个reporter.html 文件。 Reporter.html 文件中没有任何内容。

我认为,当我运行 npm run tests 并显示记者 html 页面时,reporter.html 文件会被填充。但这不会发生。

这是位桶回购的链接:https://bitbucket.org/snproject/

这是我的因果报应:

  module.exports = function(config) {
    config.set({

      basePath: '',

      frameworks: ['jasmine'],

      files: [
        {pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: true},
        {pattern: 'node_modules/angular2/bundles/angular2.js', included: true, watched: true},
        {pattern: 'node_modules/angular2/bundles/testing.js', included: true, watched: true},
        {pattern: 'node_modules/angular2/bundles/router.dev.js', included: true, watched: true},
        {pattern: 'node_modules/angular2/bundles/http.js', included: true, watched: true},      
        {pattern: 'src/firebase/firebase.js', included: true, watched: true},  

        {pattern: 'karma-test-shim.js', included: true, watched: true},

        {pattern: 'src/**/*.js', included: false, watched: true},
        {pattern: 'src/**/*.html', included: false, watched: true},
        {pattern: 'src/**/*.css', included: false, watched: true},
        {pattern: 'src/**/*.ts', included: false, watched: false},
        {pattern: 'src/**/*.js.map', included: false, watched: false}
      ],

      proxies: {
        "/app/": "/base/src/app/"
      },

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

      //This doesnt seem to work or show up????
      htmlReporter: {
        outputFile: 'reporter.html'              
      },

      port: 9877,
      colors: true,
      logLevel: config.LOG_INFO,
      autoWatch: true,
      browsers: ['Chrome'],
      singleRun: false
    })
  }

【问题讨论】:

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


    【解决方案1】:

    如果您参考karma-html-reporter 页面,您可以看到outputFile 不是记者获得的选项之一。

    显然,您无法决定输出文件的名称。您可以决定要保存结果的位置。默认情况下,报告者会创建一个名为karma_html 的文件夹,其中为每个浏览器/操作系统创建一个文件夹,其中包含一个包含测试结果的index.html 文件。

    查看您的存储库,看起来这个文件夹已创建(并且您甚至提交了它......),所以一切正常。

    【讨论】:

    • 嗨 yarons,我如何查看结果?例如,网址是什么?
    • 就像我说的,它应该在你的文件系统中,在karma_html 下。 Here it is in your repo
    【解决方案2】:

    karma-html-reporter 在 'outputDir' 中生成相对于工作目录而不是相对于 karma.conf.js 的 'basePath' 的结果

    使用kamra-htmlfile-reporter 解决了我的问题,该kamra-htmlfile-reporter 在相对于“basePath”的“outputFile”路径上正确生成了结果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-22
      • 1970-01-01
      • 2019-12-15
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多