Skip to content

Commit

Permalink
fixes #78 : Add UnitTests for components
Browse files Browse the repository at this point in the history
Setting up karma / mocha / chai framework and adding gulp task
  • Loading branch information
remie committed Sep 16, 2015
1 parent 976a326 commit a20e2dc
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
10 changes: 10 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var uglify = require('gulp-uglify');
var cssmin = require('gulp-cssmin');
var less = require('gulp-less');
var gutil = require('gulp-util');
var karma = require('gulp-karma');
var del = require('del');
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
Expand All @@ -30,6 +31,7 @@ gulp.task('browserifyAppTask', browserifyAppTask);
gulp.task('browserifyVendorTask', browserifyVendorTask);
gulp.task('copyStaticTask', copyStaticTask);
gulp.task('lessTask', lessTask);
gulp.task('testComponentsTask', testComponentsTask);

gulp.task('clean', ['cleanTask']);
gulp.task('build', ['browserifyAppTask', 'browserifyVendorTask', 'copyStaticTask', 'lessTask']);
Expand Down Expand Up @@ -92,6 +94,14 @@ function lessTask() {
.pipe(gulp.dest(paths.dist + '/css'));
};

function testComponentsTask() {
return gulp.src([])
.pipe(karma({ configFile: './test/components/karma.conf.js', action: 'run'}))
.on('error', function (err) {
throw err;
});
};

// ------------------------------------------------------------------------------------------ Functions

function log(err) {
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"date-utils": "^1.2.17",
"filesize": "^3.1.3",
"fs-extra": "^0.23.1",
"karma": "^0.13.9",
"lodash": "^3.10.1",
"md5": "^2.0.0",
"mime": "^1.3.4",
Expand Down Expand Up @@ -51,11 +52,20 @@
"gulp": "^3.9.0",
"gulp-cssmin": "^0.1.7",
"gulp-filter": "^3.0.0",
"gulp-karma": "0.0.4",
"gulp-less": "^3.0.3",
"gulp-uglify": "^1.2.0",
"gulp-util": "^3.0.6",
"jquery": "^2.1.4",
"jquery-form": "^3.50.0",
"karma-browserify": "^4.3.0",
"karma-chai": "^0.1.0",
"karma-mocha": "^0.2.0",
"karma-phantomjs-launcher": "^0.2.1",
"karma-spec-reporter": "0.0.20",
"mocha": "^2.3.2",
"phantomjs": "^1.9.18",
"proxyquireify": "^3.0.0",
"run-sequence": "^1.1.2",
"vinyl-buffer": "^1.0.0",
"vinyl-paths": "^1.0.0",
Expand Down
62 changes: 62 additions & 0 deletions test/components/karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Karma configuration
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: ['browserify', 'mocha', 'chai'],


//list of files / patterns to load in the browser
files: [
{ pattern: 'src/js/components/**/*.test.js' },
{ pattern: 'test/views/**/*.test.js' }
],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'**/*.test.js': ['browserify']
},

browserify: {
bundleDelay: 1000,
configure: function(bundle) {
bundle.once('prebundle', function() {
bundle.plugin('proxyquireify/plugin');
});
},
debug: true
},

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['spec'],

// web server port
port: 5000,

// 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: false,

// 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
});
};

0 comments on commit a20e2dc

Please sign in to comment.