Search code examples
angularunit-testinggulpcode-coveragegulp-task

How to generate coverage report through gulp task in Angular 4?


I have tried so many plugins for writing gulp task to generate coverage report in Angular 4 but no-one was working. All documentation is for javascript files and in angular 4 we have typescript files. Once I tried converting all my ts files to js files using gulp typescript and then passed those javascript references in gulp source, but finally it ends with errors.

Is there any plugin for angular 2+ to generate coverage report through gulp?

Thank you!


Solution

  • I found one solution for that using gulp-exec.

    In gulp-exec we can run any command.

    https://www.npmjs.com/package/gulp-exec

    var exec = require('child_process').exec;
    
    gulp.task('task', function (cb) {
      exec('ng test -cc', function (err, stdout, stderr) {
        console.log(stdout);
        console.log(stderr);
        cb(err);
      });
    })