When running gulp, the tests run just fine. On file change, the errors get thrown but then run and pass the tests. If I pull up the browser with tests running, it just errors out. I noticed the files aren't getting served as I specify. My current directory looks like so app bower_components node_modules public javascripts tests karma.conf.js
gulpfile.js
var gulp = require('gulp');
var karma = require('gulp-karma');
var shell = require('gulp-shell');
var testFiles = [
];
var serverDir = [
'./views/*.js',
'./test/**/*.js',
'./test/*.js',
'./routes/**/*.js',
'./routes/*.js',
'./models/**/*.js',
'./models/*.js',
'app.js'
];
gulp.task('test', function() {
// Be sure to return the stream
return gulp.src(testFiles)
.pipe(karma({
configFile: 'public/javascripts/karma.conf.js',
action: 'watch'
}))
.on('error', function(err) {
// Make sure failed tests cause gulp to exit non-zero
//throw err;
});
});
gulp.task('default', ['test', 'testServer', 'watchServerFiles']);
gulp.task('watchServerFiles', function() {
gulp.watch(serverDir, ['testServer']);
});
gulp.task('testServer', shell.task('jasmine-node-karma test/api.spec.js'));
karma.conf.js
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
'../../bower_components/angular/angular.js',
'../../bower_components/angular-mocks/angular-mocks.js',
'../../bower_components/angular-resource/angular-resource.js',
'../../bower_components/angular-route/angular-route.js',
'../../bower_components/lodash/lodash.js',
'./app.js',
'./controllers/*.js',
'./directives/*.js',
'./services/*.js',
'./*.js',
'./test/*.js',
'./test/**/*.js'
],
reporters: ['progress'],
browsers: ['PhantomJS'],
plugins: [
'karma-jasmine',
'karma-phantomjs-launcher'
],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
singleRun: false
});
};
Check this thread
Both most voted answers work well, but I decided to go with replacing gulp-karma with karma itself. The advantage is that you don't need to duplicate the list of files in both gulpfile.js and karma.conf.js files.
var gulp = require('gulp');
var karma = require('karma').server;
gulp.task('tests', function(done) {
return karma.start({
configFile: __dirname + '/test/karma.conf.js',
singleRun: true
}, done);
});