zordius / gulp-jsx-coverage

deprecated
https://www.npmjs.com/package/gulp-jsx-coverage
Other
34 stars 10 forks source link

Babel generated code included in coverage statistics #6

Closed jfairley closed 9 years ago

jfairley commented 9 years ago

I have a React app in which I am using ES6 features and leveraging the babel transpile feature of gulp-jsx-coverage. Unfortunately, the generated coverage report includes the generated ES5 code, which, of course, is not fully tested. This has managed to tank my coverage numbers. It would be better to calculate coverage numbers based on the pre-babel code.

I have the following gulp task for tests:

var jsxCoverage = require('gulp-jsx-coverage');
gulp.task('test', ['lint', 'env:test'], jsxCoverage.createTask({
    src: ['src/**/*_test.js', 'src/**/*_test.jsx'],
    istanbul: {
        coverageVariable: '__MY_TEST_COVERAGE__',
        exclude: /node_modules|tests|._test/
    },
    transpile: {
        babel: {
            include: /\.jsx?$/,
            exclude: /node_modules/
        }
    },
    coverage: {
        reporters: ['text', 'lcov', 'cobertura'],
        directory: 'coverage'
    },
    mocha: {
        reporter: 'spec'
    },
    babel: {
        sourceMap: 'inline'
    }
}));

I also have the following in one of my components:

let [markIn, markOut] = [this.state.markIn, this.state.markOut]
            .map(v => isNaN(v) ? '--:--:--:--' : timeCode.toTimeCode(v).toString());

Despite my best efforts to test for full coverage, the type-safety checks in the generated code tank the overall coverage for the file. See below including the large bit of untested, generated code on the first line.

screen shot 2015-06-11 at 9 34 03 am

zordius commented 9 years ago

Ya, based on your snapshot you still get 100% coverage on this transpiled file (functions 100% = 4/4 , lines 100% = 15/15 ) . The es5 codes still be fully tested , lines without green is ok in most cases (data structures, empty lines, sub expressions).