Skip to content

Instantly share code, notes, and snippets.

@securingsincity
Created November 28, 2014 13:30
Show Gist options
  • Save securingsincity/70187f29467876dbf653 to your computer and use it in GitHub Desktop.
Save securingsincity/70187f29467876dbf653 to your computer and use it in GitHub Desktop.
Karma Istanbul and Browserify
var gulp = require('gulp');
var browserify = require('browserify')
var source = require('vinyl-source-stream');
var istanbulTransform = require('browserify-istanbul');
var karmaServer = require('karma').server;
var glob = require('glob');
gulp.task('coverage',['build-instrument'] , function(done) {
karmaServer.start({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done)
});
//instruments the code to be
gulp.task('build-instrument', function() {
var files = glob.sync('./public/js/**.js');
return browserify({
debug: env =='development'
})
.add(files)
.transform(istanbulTransform({
ignore: ['**/node_modules/**', '**/test/**', '**/tests/**','**/**.handlebars'],
}))
.bundle()
.pipe(source('instrument.js'))
.pipe(gulp.dest('.'))
});
var istanbul = require('browserify-istanbul');
// Karma configuration
// Generated on Fri Nov 21 2014 13:33:54 GMT-0500 (EST)
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
// note the browserify framework is required
frameworks: ['browserify','mocha', 'chai'],
// list of files / patterns to load in the browser
files: [
'tests/js/**/**.js',
// the instrumented code from istanbul
'./instrument.js'
],
// list of files to exclude
exclude: [
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'tests/js/**': ['sourcemap','browserify'],
'./instrument.js': ['sourcemap']
},
browserify: {
transform: [],
debug: true,
// don't forget to register the extensions
extensions: ['.js', '.jsx', '.coffee']
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
// here the coverage reporter would be running to output the final coverage report
reporters: ['coverage'],
// 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,
browserNoActivityTimeout: 20000,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],
coverageReporter: {
reporters:[
{type: 'html', dir:'coverage/'},
{type: 'text'},
{type: 'text-summary'}
],
},
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment