karma-remap-coverage icon indicating copy to clipboard operation
karma-remap-coverage copied to clipboard

Issue with getting coverage result for Typescript project

Open geekpearl opened this issue 9 years ago • 3 comments

Hi,

I am trying to use this plugin for getting coverage report for my typescript project with systemjs builder,mocha,chai. But it is generating the report but it did not give the result. Can you please give some elaborated example for your plug in implementation.

My Karma conf is as follows: `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: ['systemjs', 'mocha', 'chai'],
systemjs: {
  configFile: 'system.config.js',
  config: {
    packages: {
      'test/unit': {
        defaultExtension: 'ts'
      },
      'src': {
        defaultExtension: 'ts'
      }
    }
  },
  serveFiles: [
               '**/*.ts'
             ]
},
plugins: ['karma-coverage', 'karma-remap-coverage','karma-systemjs', 'karma-mocha', 'karma-chai', 'karma-chrome-launcher'],
// list of files / patterns to load in the browser
files: [
  "test/unit/test.ts"
],

// list of files to exclude
exclude: [],
preprocessors: {
    './src/js/calculator.ts': ['coverage']
  },
//reporter for the test
reporters: ['progress', 'coverage', 'remap-coverage'],
coverageReporter: { type: 'in-memory' },
remapCoverageReporter: { 
	html: './coverage/html',
	cobertura: './coverage/cobertura.xml'
},
remapOptions: { basePath: './src' },
// web server port
port: 9876,

// enable / disable colors in the output
colors: true,

logLevel: config.LOG_INFO,

// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,

browsers: ['Chrome'],
 
customLaunchers: {
  Chrome_without_security: {
    base: 'Chrome',
    flags: ['--disable-web-security']
  }
},

// Continuous Integration mode
singleRun: true

}); };`

geekpearl avatar Nov 17 '16 15:11 geekpearl

See https://github.com/jp7677/hellocoreclr/blob/master/ui/karma.conf.js for a working karma.conf for JSPM/ SystemJS with the karma-jspm plugin, eventually this helps.

jp7677 avatar Dec 19 '16 18:12 jp7677

@jp7677 Your karma.conf.js does not have any rules for *.ts files.....I am having my own issue that I created here which may or may not be related to this one: #16.

I can get HTML coverage but not cobertura when using TypeScript

abobwhite avatar Mar 01 '17 16:03 abobwhite

Hi @abobwhite As far as I know it works like this:

  • Karma is doing tests on the JavaScript files and creates a coverage report for JavaScript files.
  • The JavaScript coverage report is hold in memory.
  • karma-remap-coverage then reads the report from memory and remaps the JavaScript coverage results back to typescript coverage results with the info coming from the source maps. Note the preprocessor section in my config.

So the magic comes with the source maps. You really need to make sure that your source maps are correct. Thus, at least for me, there is no need for special ts rules in the karma config. Hope this helps.

jp7677 avatar Mar 03 '17 08:03 jp7677