Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question how to exclude webpack.karma.context.js from coverage report #73

Open
andypeng2015 opened this issue Feb 8, 2017 · 0 comments

Comments

@andypeng2015
Copy link

andypeng2015 commented Feb 8, 2017

Hi Francesco @phra I found my webpack.karma.context.js is included in coverage report,how can I exclude it? thanks

context

webpack.karma.context.js
let context = require.context('./app', true, /\.js/); context.keys().forEach(context);

karma.conf.js
`var webpack = require('webpack');
var path = require('path');
var webpackConfig = require('./webpack.config');

webpackConfig.entry = {};
webpackConfig.output = {};
webpackConfig.module.preLoaders = [
{
test: /.test.js$/,
include: /app/,
exclude: /node_modules/,
loader: 'babel',
query: {
cacheDirectory: true,
},
},
{
test: /.js?$/,
include: /app/,
exclude: [/node_modules/, /.test.js$/, /webpack.karma.context.js/],
loader: 'babel-istanbul',
query: {
cacheDirectory: true,
},
},
{
test: /.html$/,
loader: 'html',
query: {
minimize: true
}
}
];

module.exports = function(config) {
config.set({
browsers: ['Chrome'],
frameworks: ['jasmine'],
reporters: ['progress', 'coverage', 'spec'],
coverageReporter: {
// output coverage reports
//type : 'html',
dir : 'coverage/',
reporters: [
{ type: 'text-summary', subdir: '.', file: 'text-summary.txt' },
{type: 'html', dir : 'coverage/',}
],
includeAllSources: true
},
logLevel: config.LOG_INFO, //config.LOG_INFO, config.LOG_DEBUG
autoWatch: true,
singleRun: false,
colors: true,
port: 9876,
basePath: '',

	webpack:webpackConfig,
	files: [ { pattern: 'webpack.karma.context.js', watched: false } ],
    preprocessors: { 'webpack.karma.context.js': ['webpack', 'sourcemap', 'coverage'] },
    exclude: [],
	webpackServer: {
		noInfo: true,
	},
	concurrency: Infinity,
	plugins:[
    require('karma-webpack'),
    'karma-chrome-launcher',
	'karma-jasmine',
	'karma-coverage',
	'karma-spec-reporter',
	'karma-sourcemap-loader'
	]
});

};`

webpack.config.js

`var webpack = require('webpack');
const prod = process.argv.indexOf('-p') !== -1;

/*

  • Default webpack configuration for development
    */
    var config = {
    devtool: 'inline-source-map', //devtool: 'source-map',
    entry: {
    ngApp : __dirname + "/app/ngApp.js",
    },
    output: {
    path: __dirname + "/public",
    filename: "[name].bundle.js"
    },
    module: {
    preLoaders: [
    {
    test: /.js?$/,
    include: /app/,
    exclude: [/node_modules/, /.test.js$/, /webpack.karma.context.js/],
    loader: 'babel',
    query: {
    cacheDirectory: true,
    },
    },
    {
    test: /.html$/,
    loader: 'html',
    query: {
    minimize: true
    }
    }
    ],
    loaders: [
    {
    test: /.js$/,
    include: /app/,
    exclude: [/node_modules/, /.test.js$/, /webpack.karma.context.js/],
    loader: 'babel',
    },
    {
    test: /.html$/,
    loader: 'html',
    query: {
    minimize: true
    }
    }
    ]
    },
    devServer: {
    contentBase: "./public",
    colors: true,
    historyApiFallback: true,
    inline: true
    },
    plugins: [
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.ProvidePlugin({
    $: 'jquery',
    jQuery: 'jquery'
    })
    ]
    }

if (prod) { config.devtool = false;
config.plugins.push( new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production')
}
}) );
config.plugins.push( new webpack.optimize.UglifyJsPlugin({ minimize: true, comments: false, compressor:{warnings:false} }) );
};
module.exports = config;
`

@andypeng2015 andypeng2015 changed the title ERROR preprocessor.coverage Unexpected token question how to exclude webpack.karma.context.js from coverage report Feb 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant