karma.config.js 5.4 KB
// var webpackConfigs = require('./webpack.config.production')
var path = require('path');
var webpack = require('webpack'); 
var AssetsPlugin = require('assets-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
 

var framePath = path.resolve(__dirname, '..');
var DEBUG = !process.argv.includes('--release');
var VERBOSE = process.argv.includes('--verbose'); 
var AUTOPREFIXER_BROWSERS = [
  'Android 2.3',
  'Android >= 4',
  'Chrome >= 35',
  'Firefox >= 31',
  'Explorer >= 9',
  'iOS >= 7',
  'Opera >= 12',
  'Safari >= 7.1',
]; 
var GLOBALS = {
  'process.env.NODE_ENV': DEBUG ? '"development"' : '"production"',   
  __DEV__: DEBUG,
  '__DEBUG__'    : DEBUG,
  '__DEBUG_NW__' : false
};

var TEST_BUNDLER = path.resolve(__dirname, '../tests/test-bundler.js');

var karmaConfig = { 
  browsers: ['Chrome'],
  singleRun: false,
  coverageReporter: {
    reporters: [
      { type: 'text-summary' },
    ],
  },  
  files: [/*'./src/public/js/plupload.full.min.js',
    './src/public/js/jquery-1.9.1.js',*/
    {
    pattern  : TEST_BUNDLER,
    watched  : false,
    served   : true,
    included : true
  }],
  frameworks: ['mocha'],
  reporters: ['mocha'],
  preprocessors: {
    [TEST_BUNDLER]  :  ['webpack'] 
  },  
  logLevel: 'WARN',
  browserConsoleLogOptions: {
    terminal: true,
    format: '%b %T: %m',
    level: '',
  },
  webpack: {
    entry: TEST_BUNDLER,
    devtool: 'cheap-module-source-map',
    module: {
      strictExportPresence: true,
      rules: [ 
        {
          test: /\.(js|jsx?)$/,
          loader: 'babel-loader',
          include: [
            path.resolve(__dirname, '../node_modules'),
            path.resolve(__dirname, '../src'),
            path.resolve(__dirname, '../tests')
          ],
          exclude: /node_modules/,
          options:{
            cacheDirectory: DEBUG,
            babelrc: false,
            presets: [
              'react',
              'es2015',
              'stage-0',
            ],
            env:{
              development:{
                plugins:[
                  ['react-transform', {
                    transforms: [{
                      transform: 'react-transform-hmr',
                      imports: ['react'],
                      locals: ['module']
                    }, {
                      transform: 'react-transform-catch-errors',
                      imports: ['react', 'redbox-react']
                    }]
                  }]
                ]
              }
            },
            plugins: [
              'transform-runtime',
              'add-module-exports'
            ]
          }
        },{
          test: /\.les$/, 
          use: [
            {
              loader: 'style-loader'
            },
            {
              loader: 'css-loader',
              options: {
                // CSS Loader https://github.com/webpack/css-loader
                importLoaders: 1,
                sourceMap: DEBUG,
                // CSS Modules https://github.com/css-modules/css-modules
                modules: true,
                localIdentName: DEBUG
                  ? '[name]_[local]_[hash:base64:3]'
                  : '[hash:base64:4]',
                // CSS Nano http://cssnano.co/
                minimize: DEBUG ? false : minimizeCssOptions,
              }
            },
            { 
              loader: 'less-loader' 
            }  
          ]
        },{
          test: /\.less$/,
          use: [  
            {
              loader: 'style-loader'
            },
            {
              loader: 'css-loader',
              options: { 
                importLoaders: 1,
                sourceMap: DEBUG,  
                minimize: DEBUG ? false : minimizeCssOptions,
              }
            },
            { 
              loader: 'less-loader' 
            }
          ]
        },{
          test: /\.css$/,
          use: [
            {
              loader: 'style-loader'
            },
            {
              loader: 'css-loader',
              options: {  
                sourceMap: DEBUG,  
                minimize: DEBUG ? false : minimizeCssOptions,
              }
            }, 
            { 
              loader: 'postcss-loader', 
              options: { 
                config: {path:path.resolve(__dirname, '../tools/postcss.config.js')} 
              } 
            }
          ]
        },{
          test: /\.json$/,
          loader: 'json-loader',
        }, {
          test: /\.txt$/,
          loader: 'raw-loader',
        }, {
          test: /\.(png|jpg|jpeg|gif|svg|woff|woff2)$/,
          loader: 'url-loader',
          options:{
            name: DEBUG ? '[path][name].[ext]?[hash]' : '[hash].[ext]',
            limit: 10000,
          }
        }, {
          test: /\.(eot|ttf|wav|mp3)$/,
          loader: 'file-loader',
          options: {
            name: DEBUG ? '[path][name].[ext]?[hash]' : '[hash].[ext]',
          }
        },
      ],
    },
    plugins: [
      new webpack.DefinePlugin(GLOBALS), 
      new webpack.optimize.OccurrenceOrderPlugin(true)
    ],
    resolve: {
      modules: ['node_modules'],
      extensions: ['.les', '.webpack.js', '.web.js', '.js', '.jsx', '.json','.less'] 
    },
    externals: {
      'react/addons': 'react',
      'react/lib/ExecutionEnvironment': 'react',
      'react/lib/ReactContext': 'react',
    },
  },
  webpackMiddleware: {
    stats: 'errors-only',
    noInfo: true,
  },
}

module.exports = function (cfg){
  cfg.set(karmaConfig);
}