dylanb / gulp-coverage

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

Untested files should show up in the coverage report (and for the enforce task) #19

Closed fakewaffle closed 9 years ago

fakewaffle commented 10 years ago

I don't have any tests for the bootstrap directory. I think the files should still show up in the coverage report (showing 0% coverage). This is very important for the enforce task, as someone could just not write any tests and pass. What are your thoughts?

'use strict';

// Load other modules
var gulp  = require( 'gulp' );
var glob  = require( 'glob' );
var mocha = require( 'gulp-mocha' );
var cover = require( 'gulp-coverage' );

// File patterns to instrument
var bootstrap   = 'bootstrap/*.js';
var controllers = 'controllers/**/*.js';
var events      = 'events/**/*.js';
var middleware  = 'middleware/**/*.js';
var models      = 'models/**/*.js';

// Test files pattern
var tests = glob.sync( 'test/**/*.js' );

gulp.task( 'default', function () {
    gulp.src( tests, { 'read' : false } )

        .pipe( cover.instrument( {
            'pattern'        : [ bootstrap, controllers, events, middleware, models ],
            'debugDirectory' : 'debug'
        } ) )

        .pipe( mocha( { } ) )

        .pipe( cover.report( {
            'outFile' : 'coverage.html'
        } ) )

        .pipe( cover.enforce() );
} );
dylanb commented 10 years ago

I think that is a good idea. I assume you are suggesting that all files that match the glob pattern would be included in the report?

fakewaffle commented 10 years ago

Yes! I think it would more accurately represent coverage.

dylanb commented 10 years ago

Do you want to submit a PR for this functionality?

fakewaffle commented 10 years ago

Sure, I don't mind looking into it. Could you point me in the right direction? Do you know what would be filtering files out?

dylanb commented 10 years ago

It is not a case of filtering files out, it is a case of the file never being required and therefore never generating any data. If the file never generates any data, the reporting does not know it exists. So you would have to find a way to force require all the files that match so that instrumentation data gets generated.

If you are not comfortable doing the PR, thats ok, I just don't want you and me working on the same thing :-)

fakewaffle commented 10 years ago

Makes sense.

I'd feel more comfortable with you doing it. :)

dylanb commented 10 years ago

ok, I will put this in line for the next release :-)

dylanb commented 9 years ago

Implemented in version 0.2.25 which was published today