dylanb / gulp-coverage

Gulp coverage reporting for Node.js that is independent of the test runner
MIT License
60 stars 12 forks source link

0% line coverage, 0% statement coverage, 0% block coverage, 0 SLOC...? #32

Closed jamesmorgan closed 10 years ago

jamesmorgan commented 10 years ago

I have been unable to successfully generate code coverage for my nodejs test code and wondered if there may be in issue with either the version of gulp-jasmine or some other dependency I am using?

The gulp task I am running looks like this:

gulp.task('server-unit-tests', function () {
    return gulp.src('./server/**/*.js', { read: false })
        .pipe(cover.instrument({
            pattern: ['./server/test/**/*.spec.js']
        }))
        .pipe(jasmine({
            verbose: true,
            includeStackTrace: true
        }))
        .pipe(cover.gather())
        .pipe(cover.format([
            { reporter: 'html', outFile: 'coverage.html' },
            { reporter: 'json', outFile: 'coverage.json' }
        ]))
        .pipe(gulp.dest('./server/coverage'));
});

This generates the following .json file:

{
 "files": [],
 "sloc": 0,
 "ssoc": 0,
 "sboc": 0,
 "coverage": null,
 "statements": null,
 "blocks": null,
 "uncovered": [
  "server/test/config.spec.js",
  "server/test/utils/cypher-promise.spec.js"
 ]
}

The html output looks like: screenshot 2014-10-06 22 13 26

I originally thought it maybe due to a different version of one of the libraries but when I checked out the latest code from here and when I run gulp on gulp-coverage I always see one of the jasmine test showing as 0% coverage and wondered if this could be related?

screenshot 2014-10-06 22 15 57

My package versions:

{
    "gulp": "^3.8.8",
    "gulp-coverage": "^0.3.31",
    "gulp-jasmine": "^1.0.0"
}

Have I missed something obvious?

dylanb commented 10 years ago

Yes, you have your tests and your source code switched around in the task.

The gulp.src('/mytests/**.js') line should match the test files. So in your case, I would expect it to have the following glob './server/test/**/*.spec.js' (that is unless you have named your test directory illogically.

The cover.instrument line should contain a glob that matches the files with the functionality that you want to ensure is covered by your tests. I don't know what this should be in your case but it is not what you have supplied.

I hope this helps

jamesmorgan commented 10 years ago

Yes you are correct, sorry I was confused.

This is the config which gives me coverage :+1:

gulp.task('server-unit-tests', function () {
    return gulp.src('./server/test/**/*.spec.js')
        .pipe(cover.instrument({
            pattern: ['./server/src/**/*.js']
        }))
        .pipe(jasmine({
            verbose: true,
            includeStackTrace: true
        }))
        .pipe(cover.gather())
        .pipe(cover.format([
            { reporter: 'html', outFile: 'coverage.html' },
            { reporter: 'json', outFile: 'coverage.json' }
        ]))
        .pipe(gulp.dest('./server/coverage'));
});
miparnisari commented 7 years ago

I have the same problem with this code: https://github.com/miparnisari/node-cognitive-services/tree/fixes

Any ideas? Here is my gulpfile:

var gulp = require('gulp');
var mocha = require('gulp-mocha');
var cover = require('gulp-coverage');

gulp.task('test', () => {
    return gulp.src('test/*.js')
        .pipe(cover.instrument({
            pattern: ['index.js', 'api/*.js', 'lib/*.js'],
            debugDirectory: 'debug'
        }))
        .pipe(mocha({
            timeout: 15000
        }))
        .pipe(cover.gather())
        .pipe(cover.format([
            { reporter: 'html', outFile: 'coverage.html' },
            { reporter: 'json', outFile: 'coverage.json' }
        ]))
        .pipe(gulp.dest('reports'));
});