Giter Club home page Giter Club logo

Comments (6)

prbaron avatar prbaron commented on May 24, 2024 3

I have been able to make it work, here are my changes :
tsconfig.json

"compilerOptions": {
  "inlineSourceMap": true,
}

webpack-test.conf.js

postLoaders : [
  {
    test: /^((?!\.spec\.ts).)*.ts$/,
    exclude: /(node_modules|tests)/,
    loader: 'istanbul-instrumenter' // used to to get the code coverage for TypeScript
  }
];

karma.conf.js

reporters: ['progress', 'coverage'],
coverageReporter: {
  reporters: [
    {
      dir: 'coverage',
      subdir: '.',
      type: 'json'
    }
  ]
},
plugins: [
  require('karma-coverage'),
]

Then in gulp_tasks/karma.js

const remapIstanbul = require('remap-istanbul/lib/gulpRemapIstanbul');
gulp.task('remap-istanbul', function() {
  return gulp.src('coverage/coverage-final.json')
    .pipe(remapIstanbul({
      reports: {
        'json': 'coverage/coverage-final.json',
        'html': 'coverage/html'
      }
    }));
});

gulpfile.js

gulp.task('test', gulp.series('karma:single-run', 'remap-istanbul'));

Then do not forget to install the dependencies.

npm i --save-dev istanbul-instrumenter-loader karma-coverage remap-istanbul

And now you should be able to get the code coverage for you project.

BONUS : since the sourcemap is done in TypeScript, you can remove the one from webpack

webpack-test.conf.js

devtool: false;

from generator-fountain-webapp.

Swiip avatar Swiip commented on May 24, 2024

I don't know any satisfying solution to have coverage for TS. So right now, there is none.

from generator-fountain-webapp.

JimLynchCodes avatar JimLynchCodes commented on May 24, 2024

How about Chutzpah or remap-instanbull?

http://stackoverflow.com/questions/17026959/code-coverage-for-typescript

from generator-fountain-webapp.

WilliamChelman avatar WilliamChelman commented on May 24, 2024

@prbaron Thanks for the hack, I just had an issue with the postLoader, none of my .ts were processed, I had to change the regex used:

postLoaders : [
  {
    test: /\.ts$/,
    exclude: /(node_modules|tests|(.spec\.ts))/,
    loaders: ['istanbul-instrumenter'] // used to to get the code coverage for TypeScript
  }
]

from generator-fountain-webapp.

prbaron avatar prbaron commented on May 24, 2024

@Nephidream You are correct. The right regex is test: /^((?!\.spec\.ts).)*.ts$/. I updated my answer according to it.

from generator-fountain-webapp.

Swiip avatar Swiip commented on May 24, 2024

Sorry for the delay. This is great, we should include it.

from generator-fountain-webapp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.