Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Transpiled sources #17

Closed
dmackerman opened this issue Dec 28, 2015 · 6 comments
Closed

Transpiled sources #17

dmackerman opened this issue Dec 28, 2015 · 6 comments

Comments

@dmackerman
Copy link

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
Copy link

nkbt commented Dec 28, 2015

@dmackerman
Copy link
Author

EDIT: My mistake, read your code wrong.

@nkbt
Copy link

nkbt commented Dec 28, 2015 via email

@dmackerman
Copy link
Author

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
Copy link

nkbt commented Dec 28, 2015

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
Copy link

ghost commented Jun 12, 2017

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

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants