diff --git a/createWebpackConfig.js b/createWebpackConfig.js index 7038cf3..fadd68d 100644 --- a/createWebpackConfig.js +++ b/createWebpackConfig.js @@ -1,8 +1,11 @@ 'use strict'; /* eslint strict:0, no-var:0, func-names:0 */ var webpack = require('webpack'); -module.exports = function createWebpackConfig(options) { - var config = { +module.exports = function createWebpackConfig(_options) { + var config; + var options = _options || {}; + + config = { plugins: [ new webpack.optimize.OccurrenceOrderPlugin(), ], diff --git a/gulpfile.js b/gulpfile.js index e270a44..5379865 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,4 +1,5 @@ 'use strict'; /* eslint strict:0, no-var:0, func-names:0 */ +var path = require('path'); var gulp = require('gulp'); var babel = require('gulp-babel'); @@ -8,9 +9,10 @@ var excludeGitignore = require('gulp-exclude-gitignore'); var mocha = require('gulp-mocha'); var nsp = require('gulp-nsp'); var rimraf = require('rimraf'); -var watch = require('gulp-watch'); var webpack = require('webpack-stream'); +var KarmaServer = require('karma').Server; + var createWebpackConfig = require('./createWebpackConfig.js'); // Initialize the babel transpiler so ES2015 files gets compiled @@ -33,11 +35,20 @@ gulp.task('nsp', function(cb) { nsp('package.json', cb); }); -gulp.task('test', function() { +gulp.task('test', ['test:karma', 'test:node']); + +gulp.task('test:node', function() { return gulp.src('test/**/*.js') .pipe(mocha({reporter: 'spec'})); }); +gulp.task('test:karma', function(done) { + new KarmaServer({ + configFile: path.join(__dirname, 'karma.conf.js'), + singleRun: true, + }, done).start(); +}); + gulp.task('babel', function() { return gulp.src('lib/**/*.js') .pipe(babel()) @@ -45,8 +56,8 @@ gulp.task('babel', function() { }); gulp.task('watch', function() { - watch(['lib/**/*.js', 'test/**/*.js'], batch(function(events, done) { - gulp.start('test', done); + gulp.watch(['lib/**/*.js', 'test/**/*.js'], batch(function(events, done) { + gulp.start('test:node', done); })); }); diff --git a/karma.conf.js b/karma.conf.js new file mode 100644 index 0000000..4d73cb5 --- /dev/null +++ b/karma.conf.js @@ -0,0 +1,72 @@ +'use strict'; /* eslint strict:0, no-var:0, func-names:0 */ + +var createWebpackConfig = require('./createWebpackConfig'); + +module.exports = function(config) { + config.set({ + + // base path that will be used to resolve all patterns (eg. files, exclude) + basePath: '', + + + // frameworks to use + // available frameworks: https://npmjs.org/browse/keyword/karma-adapter + frameworks: ['mocha'], + + + // list of files / patterns to load in the browser + files: [ + 'test/**/*.js', + ], + + // list of files to exclude + exclude: [ + ], + + + // preprocess matching files before serving them to the browser + // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor + preprocessors: { + 'test/**/*.js': ['webpack'], + }, + + webpack: createWebpackConfig(), + + webpackMiddleware: { + noInfo: true, + watch: true, + }, + + // test results reporter to use + // possible values: 'dots', 'progress' + // available reporters: https://npmjs.org/browse/keyword/karma-reporter + reporters: ['mocha'], + + + // web server port + port: 9876, + + + // enable / disable colors in the output (reporters and logs) + colors: true, + + + // level of logging + // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.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: ['PhantomJS'], + + + // Continuous Integration mode + // if true, Karma captures browsers, runs the tests and exits + singleRun: false, + }); +}; diff --git a/package.json b/package.json index 74f4a7f..5cd5f79 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,16 @@ "gulp-exclude-gitignore": "^1.0.0", "gulp-mocha": "^2.0.0", "gulp-nsp": "^0.4.5", - "gulp-watch": "^4.3.4", + "karma": "^0.13.3", + "karma-babel-preprocessor": "^5.2.1", + "karma-chrome-launcher": "^0.2.0", + "karma-mocha": "^0.2.0", + "karma-mocha-reporter": "^1.0.4", + "karma-phantomjs-launcher": "^0.2.0", + "karma-webpack": "^1.7.0", "lodash": "^3.0.0", + "mocha": "^2.2.5", + "phantomjs": "^1.9.17", "rimraf": "^2.4.2", "webpack": "^1.10.5", "webpack-stream": "^2.1.0"