Skip to content

Commit

Permalink
Add Karma to run tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leocaseiro committed Sep 2, 2015
1 parent 2058a24 commit 376d79f
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 33 deletions.
11 changes: 5 additions & 6 deletions gulp.config.js
@@ -1,13 +1,12 @@
module.exports = function() {
var dist = './dist/',
var assets = './src/',
dist = './dist/',
config = {
js : './dist/js/*.js',

// JS
jsDir: './*.js',
// Src
jsSrc: assets + './*.js',

//Dest
jsDirDest: dist + './js/'
jsDest: dist
};

return config;
Expand Down
58 changes: 34 additions & 24 deletions gulpfile.js
@@ -1,40 +1,50 @@
var gulp = require( 'gulp' ),
args = require( 'yargs' ).argv,
del = require( 'del' ),
$ = require('gulp-load-plugins')({lazy: true} ),
config = require('./gulp.config.js')(),
build = false;
var gulp = require( 'gulp' ),
del = require( 'del' ),
Karma = require( 'karma' ).Server,
$ = require( 'gulp-load-plugins' )( { lazy: true } ),
config = require( './gulp.config.js' )();

// List Tasks by default
gulp.task( 'default' , $.taskListing);
gulp.task( 'default', $.taskListing );

gulp.task( 'javascripts', function() {
return gulp.src( './jquery.stringToSlug.js' )
gulp.task( 'hint', function() {
return gulp.src( config.jsSrc )
.pipe( $.plumber() )
.pipe( $.jshint() )
.pipe( $.jshint.reporter( 'jshint-stylish', { verbose: true } ) )
.pipe( $.jscs() )
} );

gulp.task('clean-javascripts', function(done){
$.if( args.build, clean(config.jsDirDest + '**/*.*', done) );
});

gulp.task('build', ['bower', 'clean-javascripts', 'javascripts'], function(done){
return gulp.src( './jquery.stringToSlug.js' )
gulp.task( 'minify', [ 'hint', 'clean-javascripts' ], function() {
return gulp.src( config.jsSrc )
.pipe( $.plumber() )
.pipe( $.uglify( { mangle: true } ) )
.pipe( $.rename( { extname: '.min.js' } ) )
.pipe( gulp.dest( '.' ) )
});
.pipe( gulp.dest( config.jsDest ) )
} );

gulp.task( 'tests', [ 'minify' ], function() {
new Karma( {
configFile: __dirname + '/karma.conf.js',
singleRun: true
} ).start();
} );

gulp.task('watcher', ['bower', 'javascripts'], function() {
gulp.watch([config.jsDir], ['javascripts']);
});
gulp.task( 'build', [ 'tests' ] );

gulp.task( 'clean-javascripts', function() {
del( config.jsDest );
} );

gulp.task( 'watcher', [ 'bower', 'minify' ], function() {
gulp.watch( [ config.jsSrc ], [ 'minify' ] );
} );

function clean(path, done) {
del(path, done);
function clean( path, done ) {
del( path, done );
}

// Make sure all libraries are up to date
gulp.task( 'bower', function () {
run( 'bower install' ).exec();
gulp.task( 'bower', function() {
$.run( 'bower install' ).exec();
} );
69 changes: 69 additions & 0 deletions karma.conf.js
@@ -0,0 +1,69 @@
// Karma configuration
// Generated on Wed Sep 02 2015 18:41:40 GMT+1000 (AEST)

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: ['qunit'],


// list of files / patterns to load in the browser
files: [
{pattern: './bower_components/jquery/dist/jquery.min.js'},
{pattern: './bower_components/speakingurl/speakingurl.min.js'},
{pattern:'./dist/jquery.stringToSlug.min.js'},
{pattern: './tests/tests.js'}
],


// list of files to exclude
exclude: [
'karma.conf.js'
],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},


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


// 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: 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: true
})
}
9 changes: 6 additions & 3 deletions package.json
Expand Up @@ -27,7 +27,7 @@
"type": "git",
"url": "git+https://github.com/leocaseiro/jQuery-Plugin-stringToSlug.git"
},
"author": "@leocaseiro",
"author": "Leo Caseiro",
"license": "GPL-3.0",
"bugs": {
"url": "https://github.com/leocaseiro/jQuery-Plugin-stringToSlug/issues"
Expand All @@ -40,11 +40,14 @@
"gulp-jscs": "^2.0.0",
"gulp-jshint": "^1.11.2",
"gulp-load-plugins": "^0.10.0",
"gulp-plumber": "^1.0.1",
"gulp-rename": "^1.2.2",
"gulp-run": "^1.6.10",
"gulp-task-listing": "^1.0.1",
"gulp-uglify": "^1.4.0",
"jshint-stylish": "^2.0.1",
"run": "^1.4.0",
"yargs": "^3.23.0"
"karma": "^0.13.9",
"karma-phantomjs-launcher": "^0.2.1",
"karma-qunit": "^0.1.5"
}
}

0 comments on commit 376d79f

Please sign in to comment.