karma-jspm icon indicating copy to clipboard operation
karma-jspm copied to clipboard

Code coverage with karma-jspm

Open tauren opened this issue 9 years ago • 14 comments

I'm using karma-coverage along with karma-jspm. Coverage reports are being generated, but only for source files that are referenced in test files. However, any source files that are not required from a test file doesn't show up in the coverage report.

Is this is because karma-jspm highjacks the karam files config, only including files that are referenced? Any ideas on how to get the coverage reports to list all source files so the reporting is more accurate?

Here's relevant portions of my karma config:

  config.set({
    frameworks: ['jspm','mocha','sinon-chai'],
    jspm: {
      loadFiles: ['app/**/test/**/*.test.js'],
      serveFiles: ['app/**/lib/**/*.js']
    },
    proxies: {
      '/jspm_packages/': '/base/jspm_packages/'
    },
    preprocessors: {
      'app/**/lib/**/*.js': ['coverage']
    }
};

I've attempted to include both tests and source files in jspm.loadFiles, but it blows up with errors. These are errors I may be able to resolve, but wanted to first find out if there is a better approach I should be taking.

tauren avatar Nov 10 '14 13:11 tauren

+1

katrotz avatar Jan 03 '15 22:01 katrotz

+1

tinkertrain avatar Jan 14 '15 00:01 tinkertrain

+1

djindjic avatar Jan 28 '15 21:01 djindjic

+1

andreasgrimm avatar Feb 12 '15 19:02 andreasgrimm

@tauren I can't get coverage reports working at all when trying to use on-the-fly transpilation (which is what karma-jspm is doing here I guess). I see a lot of other examples where coverage runs against already transpiled sources though (where transpiling happens during karma-preprocessing).

I thought it might be helpful to see your complete karma config in case I'm missing something here (like maybe you are using Chrome instead of PhantomJS or something like that).

andreasgrimm avatar Feb 18 '15 22:02 andreasgrimm

+1

robcleghorn avatar Mar 15 '15 21:03 robcleghorn

+1 I can't get coverage reports working

Bretto avatar Mar 17 '15 03:03 Bretto

+1 getting some feedback on whether this project is still active would be great

vincentbriglia avatar Mar 30 '15 08:03 vincentbriglia

Code coverage using karma-coverage should work as expected. Be sure to include the preprocessor configuration in karma.conf.js:

preprocessors = {
    'build/src/**/*.js': ['coverage']
};
reporters = ['progress', 'coverage'];

Where build/src/ is the location from where your source files are being required/loaded.

The original issue that @tauren is indeed a valid issue, though. If the test runner does not end up loading some of your source, it will not be included in the coverage report. If this is a problem for you I would suggest trying to put all source and test files in jspm.loadFiles... and if that doesn't work for you I'd create a dummy test file that simply requires all the source files that you want to test.

maxwellpeterson-wf avatar Mar 30 '15 14:03 maxwellpeterson-wf

It seems like coverage doesn't include transpiler over karma-jspm into my tests execution if I have coverage configuration. I am getting:

ERROR [preprocessor.coverage]: Line 1: Unexpected reserved word

Line 1 is starting with 'import'. Here is my karma.config. Could you guys please take a look @maxwellpeterson-wf @tauren?

djindjic avatar Apr 03 '15 07:04 djindjic

@djindjic ,

In case it's useful, I was getting the same error. I believe it was due to my serveFiles files not being transpiled. As a workaround, I added the karma-babel-preprocessor to transpile before coverage:

/* related karma.conf.js fragment */

frameworks: ['jspm', 'jasmine'],

jspm: {
  loadFiles: ['app/**/*spec.js'],
  serveFiles: ['app/**/*.js', 'app/**/*.html']
},

files: [/* defers to async loading by jspm framework */],

preprocessors: {
  'app/**/!(*spec).js': ['babel', 'coverage'],
},

// transpile with babel since the coverage reporter throws error on ES6 syntax
babelPreprocessor: {
  options: {
    modules: 'system'
  }
},
reporters: ['progress', 'coverage'],

twalker avatar Apr 04 '15 22:04 twalker

has anybody got running the coverage? @djindjic I tried run the preprocessor for coverage as you have suggested but all my test are failing

martinmicunda avatar Aug 17 '15 11:08 martinmicunda

I just did what @twalker suggested and mine works perfectly. Thanks!

jgodi avatar Aug 21 '15 13:08 jgodi

In case anyone ends up here wondering how to include all source files (@tauren's original question), karma-coverage added this parameter recently (last few months) :

    coverageReporter: {
      type : 'html',
      dir : 'coverage/',
      includeAllSources : true // <-- This aptly named param brings in all sources.
    },

Changeset: https://github.com/karma-runner/karma-coverage/pull/131

tannerlyons avatar Dec 04 '15 08:12 tannerlyons