webpack-contrib / istanbul-instrumenter-loader

Istanbul Instrumenter Loader
MIT License
273 stars 65 forks source link

Transpiled sources #17

Closed dmackerman closed 8 years ago

dmackerman commented 8 years ago

I got this working, but the coverage is showing my transpiled sources. I've spent hours trying to figure out which modules to use to get the ES6 code to be shown by Istanbul.

Do I need something like isparta-loader? I tried plugging it in as a preLoader, but no dice.

My karma.config

module.exports = function(config) {
    config.set({

        // use headless PhantomJS
        browsers: ['Chrome'],

        // use Jasmine with Sinon for mocking and stubs
        frameworks: ['jasmine', 'sinon'],

        // load our single entry point for our tests
        files: [
            'tests/tests.webpack.js'
        ],

        // preprocess with webpack and our sourcemap loader
        preprocessors: {
            'tests/tests.webpack.js': ['webpack', 'sourcemap']
        },

        reporters: [
            // https://github.com/mlex/karma-spec-reporter
            'spec',

            // https://github.com/karma-runner/karma-coverage
            'coverage'
        ],

        // configure webpack within Karma
        webpack: {

            // just do inline source maps instead of the default
            devtool: 'inline-source-map',

            module: {
                loaders: [{
                    test: /\.js/,
                    exclude: /node_modules/,
                    loader: 'babel-loader'
                }, {
                    test: /\.html$/,
                    loader: 'html'
                }],
                // delays coverage til after tests are run, fixing transpiled source coverage error
                postLoaders: [{
                    test: /\.js$/,
                    exclude: /(tests|node_modules|\.spec\.js$)/,
                    loader: 'istanbul-instrumenter'
                }]
            }
        },

        // configure the webpack server to not be so verbose
        webpackServer: {
            noInfo: true
        },

        // setup code coverage
        coverageReporter: {
            reporters: [{
                type: 'text-summary',
            }, {
                type: 'html',
                dir: 'coverage/'
            }]
        },

    });
};

My tests.webpack.js is my single entry point.

var context = require.context('../src', true, /\.js$/);
context.keys().forEach(context);
nkbt commented 8 years ago

@dmackerman see https://github.com/nkbt/esnext-quickstart/blob/master/karma.conf.js

dmackerman commented 8 years ago

EDIT: My mistake, read your code wrong.

nkbt commented 8 years ago

One for coverage, one for just tests. Cov is pretty slow, so I rarely run it

dmackerman commented 8 years ago

Hmm, it appears that my code isn't being transpiled. I get warnings like:

WARNING in ./test/about/about.spec.js
Module parse failed: /Users/dave/Sites/ionic-seed/node_modules/babel-loader/index.js!/Users/dave/Sites/ionic-seed/test/about/about.spec.js Line 1: Unexpected token
You may need an appropriate loader to handle this file type.
| import AboutController from './about.controller';
|
| describe('About Component', () => {
 @ ./test \.spec\.js$

But I thought the Babel loader was handling those...

nkbt commented 8 years ago

If you are using babel6 (I reckon you do), you need presets. es2015 at least. And add it to .babelrc or package.json. See babel site for reference. Or esnext-quickstart for working configs.

ghost commented 7 years ago

excluding in webpack, yours is the only expression that worked!

/(tests|node_modules|\.spec\.ts$)/