AngularM
AngularM

Reputation: 16618

How to get Karma html reporter working in karma conf?

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.org/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
    })
  }

Upvotes: 5

Views: 9612

Answers (2)

kksodha
kksodha

Reputation: 21

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'.

Upvotes: 2

Yaron Schwimmer
Yaron Schwimmer

Reputation: 5357

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 committed it...), so everything works.

Upvotes: 1

Related Questions