pocesar/grunt-mocha-istanbul

Covering bower_components folder

Closed this issue · 4 comments

Hello,

One dependency of my project is being covered by istanbul. Look at the image below, the public/bower_components/underscore/ shouldn't be there.
0

This is my gruntfile:

        mochaTest: {
            test: {
                options: {
                    reporter: 'spec',
                    quiet: false, // Optionally suppress output to standard out (defaults to false)
                    clearRequireCache: false, // Optionally clear the require cache before running tests (defaults to false)
                    ignoreLeaks: false, // Check for global variable leaks,
                    require: 'test/globals.js'
                },
                src: grunt.option('only') ? [grunt.option('only')] : ['test/**/*.js']
            }
        },
        mocha_istanbul: {
            coverage: {
                src: 'test/**/*Test.js', // test folder
                options: {
                    require: ['test/globals.js'],
                    check: {
                        lines: 80,
                        statements: 80,
                        branches: 60,
                        functions: 70
                    },
                    print: 'summary'
                }
            }
        }

Any thoughts of what might be wrong?

Thanks,

Jaime

if all your tests are running against files inside the app folder, set options: { root: 'app' }, and only files inside app folder will be instrumented. anything outside won't be considered.

another option is to use options: { excludes: ['bower_components'] }, so it will exclude bower_components from the report. or use options: { includes: ['app'] } to fine grain the sources that should be included in the report

Thanks Paulo, using excludes made it work! But I think it wouldn't be necessary to do this in the first place. All my tests are inside the test folder and I have the src set src: 'test/**/*Test.js'. I think this is saying that istanbul will look only inside that folder. Is that correct?

the src only defines your test sources. if your application files import or reference other file paths, istanbul will follow. when using globals, and they are not defined in your configurations as well, I think istanbul will try to resolve them as well (can't confirm)

another reason could be the globals.js file that is being included as sources file (and referencing to lodash), since it's not matching against the tests/**Test.js glob, and is being instrumented as part of your app

Yes Paulo, I think you are right. I also suspects of globals.js. Thanks for the help!