gotwarlost / istanbul

Yet another JS code coverage tool that computes statement, line, function and branch coverage with module loader hooks to transparently add coverage when running tests. Supports all JS coverage use cases including unit tests, server side functional tests and browser tests. Built for scale.
Other
8.7k stars 787 forks source link

Weird behaviour on else branch coverage #812

Open gpincheiraa opened 7 years ago

gpincheiraa commented 7 years ago

I having a weird behaviour when the reporter shows me the branch coverage else-statement even if this code is under cover by my tests. The problem it's that always shows a else branch coverage in the same line ... even if i swap the lines!!

My config is the following:

karma.conf.js

var webpack = require('webpack');

module.exports = function(config) {
    var wsPort = process.env.wsPort || 8000;
    var webpackConfig = Object.assign({}, config.webpack, {
        plugins: config.webpack.plugins.concat([
            new webpack.SourceMapDevToolPlugin({
                filename: null,
                test: /\.js/i
            })
        ]),
        module: Object.assign({}, config.webpack.module, {
            postLoaders: (config.webpack.module.postLoaders || []).concat([{
                test: /\.js$/,
                exclude: /(test|node_modules|bower_components)\//,
                loader: 'istanbul-instrumenter',
                options: {
                    compact: false
                }
            }])
        }),
        // Esto es necesario porque karma-webpack muta el output, causando un error al correr junto con start-main-server
        output: Object.assign({}, config.webpack.output),
        entry: undefined
    });
    return {
        files: [
            { pattern: 'test/unit/test-main.js', watched: false }
        ],
        preprocessors: {
            'test/unit/test-main.js': ['webpack', 'sourcemap']
        },
        webpack: webpackConfig,
        webpackMiddleware: {
            stats: 'errors-only'
        },
        frameworks: ['mocha', 'chai', 'chai-as-promised', 'sinon', 'sinon-chai'],
        browsers: [],
        proxies: {
            '/ws/': 'http://localhost:' + wsPort + '/ws/',
        },
        client: {
            mocha: {
                reporter: 'html' // change Karma's debug.html to the mocha web reporter
            }
        },
        singleRun: false,
        plugins: [
            'karma-webpack',
            'karma-mocha',
            'karma-mocha-reporter',
            'karma-chai-plugins',
            'karma-sinon',
            'karma-phantomjs-launcher',
            'karma-sourcemap-loader',
            'karma-coverage-istanbul-reporter',
            'karma-junit-reporter'
        ]
    };
};

karma.coverage.js (I load this configuration in a separated file using gulp)

module.exports = {
    preprocessors: {
        'test/unit/test-main.js': ['webpack', 'sourcemap'],
    },
    browsers: ['PhantomJS'],
    reporters: ['coverage-istanbul', 'mocha', 'junit'],
    coverageIstanbulReporter: {
        reports: [ 'text-summary', 'html', 'cobertura', 'lcovonly' ],
        dir: '_build',
        'report-config': {
            html: {
                subdir: 'lcov-report'
            },
            cobertura: {
                file: 'cobertura-coverage.xml'
            },
            lcovonly: {
                file: 'lcov.info'
            }
        },
        fixWebpackSourcePaths: true
    },
    junitReporter: {
        outputFile: '_build/test-reports/TEST-index.xml',
        suite: 'Unit Tests',
        useBrowserName: false
    },
    mochaReporter: {
        output: 'autowatch'
    }
};

I attached multiple screenshoots showing this.

captura de pantalla 2017-05-08 a las 8 13 15 p m Check this out images that show that if i swap the lines, the else branch it is showed always on the same line captura de pantalla 2017-05-08 a las 8 12 32 p m