最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get Karma html reporter working in karma conf? - Stack Overflow

programmeradmin0浏览0评论

How to get Karma html reporter working in karma conf?

To run my unit tests I type: "npm run test" and the tests run fine in git bash. But I want to see them in the reporter.html file.

I've made a reporter.html file next to the karma conf file in the root directory. The reporter.html file has nothing in it.

I think the reporter.html file gets populated when I run npm run tests and the reporter html page shows up. But this doesn't happen.

This is the link to the bit bucket repo: /

This is my karma conf:

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

How to get Karma html reporter working in karma conf?

To run my unit tests I type: "npm run test" and the tests run fine in git bash. But I want to see them in the reporter.html file.

I've made a reporter.html file next to the karma conf file in the root directory. The reporter.html file has nothing in it.

I think the reporter.html file gets populated when I run npm run tests and the reporter html page shows up. But this doesn't happen.

This is the link to the bit bucket repo: https://bitbucket/snproject/

This is my karma conf:

  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
    })
  }
Share Improve this question edited Dec 8, 2015 at 10:03 AngularM asked Dec 8, 2015 at 9:53 AngularMAngularM 16.6k29 gold badges102 silver badges175 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

karma-html-reporter generates results in 'outputDir' relative to working directory instead of relative to the 'basePath' of karma.conf.js

My problem was solved by using kamra-htmlfile-reporter which correctly generated results at 'outputFile' path relative to the 'basePath'.

If you refer to the karma-html-reporter page, you can see that outputFile is not one of the options the reporter gets.

Apparently, you don't get to decide about the name of the output file. You can decide where you want the results to be saved. By default, the reporter creates a folder named karma_html, in which for every browser/OS a folder is created with an index.html file, which contains the test results.

Looking at your repo, it looks like this folder was created (and you even mitted it...), so everything works.

发布评论

评论列表(0)

  1. 暂无评论