diff --git a/karma.conf.js b/karma.conf.js index e69de29..d20fbf6 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -0,0 +1,92 @@ +const webpackConfig = require('./webpack.config'); +const sauceBrowsers = require('./sauce.browsers'); + +module.exports = function (config) { + // list of files / patterns to load in the browser + // all dependancies should be traced through here + var files = ['test/unit.js']; + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + // webpack will trace and watch all dependancies + var preprocessors = { + 'test/unit.js': [ 'webpack', 'sourcemap' ] + }; + + if (process.argv.indexOf('--perf') > -1) { + files = [ require.resolve('../benchmark/benchmark.js'), 'test/perf.js' ]; + preprocessors = { + 'test/perf.js': [ 'webpack', 'sourcemap' ] + }; + } + + config.set(Object.assign({ + // base path that will be used to resolve all patterns (eg. files, exclude) + // setting to process.cwd will make all paths start in current component directory + basePath: process.cwd(), + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: [ 'mocha', 'chai', 'sinon-chai' ], + + // list of files / patterns to load in the browser + files: files, + + // list of files to exclude + exclude: [], + + // list of preprocessors + preprocessors: preprocessors, + + // karma watches the test entry points + // (you don't need to specify the entry option) + // webpack watches dependencies + webpack: Object.assign({}, webpackConfig, { + devtool: 'inline-source-map', + entry: undefined + }), + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: [ 'progress' ], + + // web server port + port: 9876, + + // enable / disable colors in the output (reporters and logs) + colors: true, + + // level of logging + // possible values: LOG_DISABLE, LOG_ERROR, LOG_WARN, LOG_INFO, LOG_DEBUG + logLevel: config.LOG_INFO, + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + // start these browsers + // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher + browsers: [ 'Chrome', 'Firefox' ], + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false, + + // Concurrency level + // how many browser should be started simultaneous + concurrency: Infinity + }, process.argv.indexOf('--saucelabs') === -1 ? {} : { + sauceLabs: { + testName: 'Unit Tests', + recordScreenshots: false, + connectOptions: { verbose: true } + }, + customLaunchers: sauceBrowsers, + browsers: Object.keys(sauceBrowsers), + captureTimeout: 120000, + reporters: [ 'saucelabs', 'dots' ], + autoWatch: false, + concurrency: 5, + client: {} + })); +}; diff --git a/webpack.conf.js b/webpack.conf.js deleted file mode 100644 index e69de29..0000000 diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..8a190ac --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,46 @@ +var camelCase = require('camelcase'); +var path = require('path'); +var webpack = require('webpack'); +var pkg = require(path.join(process.cwd(), 'package.json')); +var shouldMininimize = process.argv.indexOf('--min') !== -1; +var standardConfig = { + entry: { + 'dist/bundle.js': './src/index.js' + }, + output: { + path: './', + filename: '[name]', + libraryTarget: 'umd', + library: camelCase(pkg.name), + sourceMapFilename: '[file].map' + }, + module: { + loaders: [{ + test: /\.css$/, + loader: 'style!css' + }, { + test: /\.less$/, + loader: 'style!css!less' + }, { + loader: 'babel-loader', + test: /\.js$/, + query: { + presets: 'babel-preset-es2015' + } + }] + }, + plugins: [ + new webpack.optimize.UglifyJsPlugin({ + include: /\.min\.js$/, + minimize: true + }) + ] +}; + +if (shouldMininimize) { + Object.assign(standardConfig.entry, { + 'dist/bundle.min.js': './src/index.js' + }); +} + +module.exports = standardConfig;