nikku / karma-browserify

A fast Browserify integration for Karma that handles large projects with ease
MIT License
321 stars 50 forks source link

Code coverage with tsify #200

Closed iamolivinius closed 6 years ago

iamolivinius commented 8 years ago

Not sure if this is the right place to file this issue but your project seems to me to be a common denominator.

My goal is to get code coverage reports of a typescript project. Therefore I use the karma test runner in the following configuration.

var istanbul = require('browserify-istanbul');
module.exports = function(config) {
  config.set({
    basePath: '',
    frameworks: ['browserify', 'mocha', 'chai', 'source-map-support'],
    files: [
      'test/**/*Spec.ts'
    ],
    exclude: [
    ],
    preprocessors: {
      'test/**/*Spec.ts': ['browserify']
    },
    browserify: {
      debug: true,
      transform: [istanbul()]
    },
    reporters: ['progress', 'coverage'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: true,
    concurrency: Infinity
  })
}

src/add.ts

export function add(a: number, b: number): number {
  if (a === 0)
    return b

  if (b === 0)
    return a

  return a + b
}

test/addSpec.ts

import {add} from '../src/add'
const expect = chai.expect

describe('test add module', () => {
  it('should add 2 numbers', () => {
    expect(add(1, 2)).to.be.equal(3)
  })
})

The metrics of the coverage report seem to be ok but the annotation in the "source file view" are a bit odd.

screenshot from 2016-08-05 00-10-16

My first guess is that something with the source maps went wrong due to the multiple transformations along the process.

I hope you can provide me any information or point me in the right direction to solve this issue.

Also I filed this as a question on stackoverflow earlier today: http://stackoverflow.com/questions/38764929/how-to-do-code-coverage-with-karma-typescript-and-browserify

nikku commented 6 years ago

Closing this as WONT_FIX as this is I don't have sufficient knowledge on tsify + coverage setups to help you out on this one.