Skip to content

Commit

Permalink
Set up a foundation for testing with karma, mocha and chai.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikehaas763 committed Mar 3, 2014
1 parent c683c62 commit 027503f
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 6 deletions.
4 changes: 2 additions & 2 deletions build/knockout-bootstrap.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 21 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var header = require('gulp-header');
var karma = require('gulp-karma');
var fs = require('fs');
var pkg = require('./package.json');

var paths = {
src: 'src/' + pkg.name + '.js'
src: 'src/' + pkg.name + '.js',
spec: 'spec/'
};

// Using a banner that is stored in a file to make it easier to work with.
Expand All @@ -18,7 +20,7 @@ try {
throw new Error('There was an error reading in the banner.');
}

gulp.task('default', ['build']);
gulp.task('default', ['watch']);

gulp.task('lint', function() {
gulp.src(paths.src)
Expand All @@ -27,10 +29,26 @@ gulp.task('lint', function() {
.pipe(jshint.reporter('fail'));
});

gulp.task('build', ['lint'], function() {
gulp.task('build', ['lint', 'test'], function() {
gulp.src(paths.src)
.pipe(uglify())
.pipe(concat(pkg.name + '.min.js'))
.pipe(header(banner, { pkg: pkg, buildDate: gutil.date(new Date(), 'yyyy-mm-dd') }))
.pipe(gulp.dest('build'));
});

gulp.task('test', function() {
gulp.src(paths.spec + '**/*-spec.js')
.pipe(karma({
configFile: 'karma.conf.js',
action: 'run'
}));
});

gulp.task('watch', function() {
gulp.src(paths.spec + '**/*-spec.js')
.pipe(karma({
configFile: 'karma.conf.js',
action: 'watch'
}));
});
68 changes: 68 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Karma configuration
// Generated on Sun Mar 02 2014 20:54:04 GMT-0600 (CST)

module.exports = function(config) {
config.set({

// base path, that will be used to resolve files and exclude
basePath: '',


// frameworks to use
frameworks: ['mocha', 'chai'],


// list of files / patterns to load in the browser
files: [
'spec/**/*-spec.js'
],


// list of files to exclude
exclude: [

],


// test results reporter to use
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
reporters: ['progress'],


// 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, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera (has to be installed with `npm install karma-opera-launcher`)
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
// - PhantomJS
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
browsers: ['PhantomJS'],


// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,


// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
};
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@
"gulp-concat": "^2.1.7",
"gulp-header": "^1.0.2",
"gulp-util": "^2.2.14",
"gulp-jshint": "^1.5.0"
"gulp-jshint": "^1.5.0",
"gulp-karma": "0.0.2",
"karma-chrome-launcher": "^0.1.2",
"karma-phantomjs-launcher": "^0.1.2",
"karma-mocha": "^0.1.1",
"karma-chai": "^0.1.0"
},
"author": "Bill Pullen",
"license": "MIT",
Expand Down
5 changes: 5 additions & 0 deletions spec/test-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('Testing bdd abilities', function() {
it('should be a passing test', function() {
expect(true).to.equal(true);
})
});

0 comments on commit 027503f

Please sign in to comment.