Skip to content

Commit 376d79f

Browse files
committed
Add Karma to run tests
1 parent 2058a24 commit 376d79f

File tree

4 files changed

+114
-33
lines changed

4 files changed

+114
-33
lines changed

gulp.config.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
module.exports = function() {
2-
var dist = './dist/',
2+
var assets = './src/',
3+
dist = './dist/',
34
config = {
4-
js : './dist/js/*.js',
5-
6-
// JS
7-
jsDir: './*.js',
5+
// Src
6+
jsSrc: assets + './*.js',
87

98
//Dest
10-
jsDirDest: dist + './js/'
9+
jsDest: dist
1110
};
1211

1312
return config;

gulpfile.js

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,50 @@
1-
var gulp = require( 'gulp' ),
2-
args = require( 'yargs' ).argv,
3-
del = require( 'del' ),
4-
$ = require('gulp-load-plugins')({lazy: true} ),
5-
config = require('./gulp.config.js')(),
6-
build = false;
1+
var gulp = require( 'gulp' ),
2+
del = require( 'del' ),
3+
Karma = require( 'karma' ).Server,
4+
$ = require( 'gulp-load-plugins' )( { lazy: true } ),
5+
config = require( './gulp.config.js' )();
76

87
// List Tasks by default
9-
gulp.task( 'default' , $.taskListing);
8+
gulp.task( 'default', $.taskListing );
109

11-
gulp.task( 'javascripts', function() {
12-
return gulp.src( './jquery.stringToSlug.js' )
10+
gulp.task( 'hint', function() {
11+
return gulp.src( config.jsSrc )
12+
.pipe( $.plumber() )
1313
.pipe( $.jshint() )
1414
.pipe( $.jshint.reporter( 'jshint-stylish', { verbose: true } ) )
1515
.pipe( $.jscs() )
1616
} );
1717

18-
gulp.task('clean-javascripts', function(done){
19-
$.if( args.build, clean(config.jsDirDest + '**/*.*', done) );
20-
});
21-
22-
gulp.task('build', ['bower', 'clean-javascripts', 'javascripts'], function(done){
23-
return gulp.src( './jquery.stringToSlug.js' )
18+
gulp.task( 'minify', [ 'hint', 'clean-javascripts' ], function() {
19+
return gulp.src( config.jsSrc )
20+
.pipe( $.plumber() )
2421
.pipe( $.uglify( { mangle: true } ) )
2522
.pipe( $.rename( { extname: '.min.js' } ) )
26-
.pipe( gulp.dest( '.' ) )
27-
});
23+
.pipe( gulp.dest( config.jsDest ) )
24+
} );
25+
26+
gulp.task( 'tests', [ 'minify' ], function() {
27+
new Karma( {
28+
configFile: __dirname + '/karma.conf.js',
29+
singleRun: true
30+
} ).start();
31+
} );
2832

29-
gulp.task('watcher', ['bower', 'javascripts'], function() {
30-
gulp.watch([config.jsDir], ['javascripts']);
31-
});
33+
gulp.task( 'build', [ 'tests' ] );
34+
35+
gulp.task( 'clean-javascripts', function() {
36+
del( config.jsDest );
37+
} );
38+
39+
gulp.task( 'watcher', [ 'bower', 'minify' ], function() {
40+
gulp.watch( [ config.jsSrc ], [ 'minify' ] );
41+
} );
3242

33-
function clean(path, done) {
34-
del(path, done);
43+
function clean( path, done ) {
44+
del( path, done );
3545
}
3646

3747
// Make sure all libraries are up to date
38-
gulp.task( 'bower', function () {
39-
run( 'bower install' ).exec();
48+
gulp.task( 'bower', function() {
49+
$.run( 'bower install' ).exec();
4050
} );

karma.conf.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Karma configuration
2+
// Generated on Wed Sep 02 2015 18:41:40 GMT+1000 (AEST)
3+
4+
module.exports = function(config) {
5+
config.set({
6+
7+
// base path that will be used to resolve all patterns (eg. files, exclude)
8+
basePath: './',
9+
10+
11+
// frameworks to use
12+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
13+
frameworks: ['qunit'],
14+
15+
16+
// list of files / patterns to load in the browser
17+
files: [
18+
{pattern: './bower_components/jquery/dist/jquery.min.js'},
19+
{pattern: './bower_components/speakingurl/speakingurl.min.js'},
20+
{pattern:'./dist/jquery.stringToSlug.min.js'},
21+
{pattern: './tests/tests.js'}
22+
],
23+
24+
25+
// list of files to exclude
26+
exclude: [
27+
'karma.conf.js'
28+
],
29+
30+
31+
// preprocess matching files before serving them to the browser
32+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
33+
preprocessors: {
34+
},
35+
36+
37+
// test results reporter to use
38+
// possible values: 'dots', 'progress'
39+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
40+
reporters: ['dots'],
41+
42+
43+
// web server port
44+
port: 9876,
45+
46+
47+
// enable / disable colors in the output (reporters and logs)
48+
colors: true,
49+
50+
51+
// level of logging
52+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
53+
logLevel: config.LOG_INFO,
54+
55+
56+
// enable / disable watching file and executing tests whenever any file changes
57+
autoWatch: false,
58+
59+
60+
// start these browsers
61+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
62+
browsers: ['PhantomJS'],
63+
64+
65+
// Continuous Integration mode
66+
// if true, Karma captures browsers, runs the tests and exits
67+
singleRun: true
68+
})
69+
}

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"type": "git",
2828
"url": "git+https://github.com/leocaseiro/jQuery-Plugin-stringToSlug.git"
2929
},
30-
"author": "@leocaseiro",
30+
"author": "Leo Caseiro",
3131
"license": "GPL-3.0",
3232
"bugs": {
3333
"url": "https://github.com/leocaseiro/jQuery-Plugin-stringToSlug/issues"
@@ -40,11 +40,14 @@
4040
"gulp-jscs": "^2.0.0",
4141
"gulp-jshint": "^1.11.2",
4242
"gulp-load-plugins": "^0.10.0",
43+
"gulp-plumber": "^1.0.1",
4344
"gulp-rename": "^1.2.2",
45+
"gulp-run": "^1.6.10",
4446
"gulp-task-listing": "^1.0.1",
4547
"gulp-uglify": "^1.4.0",
4648
"jshint-stylish": "^2.0.1",
47-
"run": "^1.4.0",
48-
"yargs": "^3.23.0"
49+
"karma": "^0.13.9",
50+
"karma-phantomjs-launcher": "^0.2.1",
51+
"karma-qunit": "^0.1.5"
4952
}
5053
}

0 commit comments

Comments
 (0)