Add karma testing

This commit is contained in:
Aaron Jensen 2015-08-04 10:39:56 -07:00
parent 89d32316b6
commit 0449c1c5e1
4 changed files with 101 additions and 7 deletions

View File

@ -1,8 +1,11 @@
'use strict'; /* eslint strict:0, no-var:0, func-names:0 */ 'use strict'; /* eslint strict:0, no-var:0, func-names:0 */
var webpack = require('webpack'); var webpack = require('webpack');
module.exports = function createWebpackConfig(options) { module.exports = function createWebpackConfig(_options) {
var config = { var config;
var options = _options || {};
config = {
plugins: [ plugins: [
new webpack.optimize.OccurrenceOrderPlugin(), new webpack.optimize.OccurrenceOrderPlugin(),
], ],

View File

@ -1,4 +1,5 @@
'use strict'; /* eslint strict:0, no-var:0, func-names:0 */ 'use strict'; /* eslint strict:0, no-var:0, func-names:0 */
var path = require('path');
var gulp = require('gulp'); var gulp = require('gulp');
var babel = require('gulp-babel'); var babel = require('gulp-babel');
@ -8,9 +9,10 @@ var excludeGitignore = require('gulp-exclude-gitignore');
var mocha = require('gulp-mocha'); var mocha = require('gulp-mocha');
var nsp = require('gulp-nsp'); var nsp = require('gulp-nsp');
var rimraf = require('rimraf'); var rimraf = require('rimraf');
var watch = require('gulp-watch');
var webpack = require('webpack-stream'); var webpack = require('webpack-stream');
var KarmaServer = require('karma').Server;
var createWebpackConfig = require('./createWebpackConfig.js'); var createWebpackConfig = require('./createWebpackConfig.js');
// Initialize the babel transpiler so ES2015 files gets compiled // Initialize the babel transpiler so ES2015 files gets compiled
@ -33,11 +35,20 @@ gulp.task('nsp', function(cb) {
nsp('package.json', 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') return gulp.src('test/**/*.js')
.pipe(mocha({reporter: 'spec'})); .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() { gulp.task('babel', function() {
return gulp.src('lib/**/*.js') return gulp.src('lib/**/*.js')
.pipe(babel()) .pipe(babel())
@ -45,8 +56,8 @@ gulp.task('babel', function() {
}); });
gulp.task('watch', function() { gulp.task('watch', function() {
watch(['lib/**/*.js', 'test/**/*.js'], batch(function(events, done) { gulp.watch(['lib/**/*.js', 'test/**/*.js'], batch(function(events, done) {
gulp.start('test', done); gulp.start('test:node', done);
})); }));
}); });

72
karma.conf.js Normal file
View File

@ -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,
});
};

View File

@ -43,8 +43,16 @@
"gulp-exclude-gitignore": "^1.0.0", "gulp-exclude-gitignore": "^1.0.0",
"gulp-mocha": "^2.0.0", "gulp-mocha": "^2.0.0",
"gulp-nsp": "^0.4.5", "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", "lodash": "^3.0.0",
"mocha": "^2.2.5",
"phantomjs": "^1.9.17",
"rimraf": "^2.4.2", "rimraf": "^2.4.2",
"webpack": "^1.10.5", "webpack": "^1.10.5",
"webpack-stream": "^2.1.0" "webpack-stream": "^2.1.0"