From f61d93e17850251ff7287aa272e6d182f79ccd61 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Thu, 20 Aug 2015 02:40:42 +0200 Subject: [PATCH] showcase: wiredep in karma.conf.js file --- angularjs/showcase/gulp.config.js | 15 +++++++++++++-- angularjs/showcase/gulpfile.js | 28 +++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/angularjs/showcase/gulp.config.js b/angularjs/showcase/gulp.config.js index bac5508..e851048 100644 --- a/angularjs/showcase/gulp.config.js +++ b/angularjs/showcase/gulp.config.js @@ -39,9 +39,20 @@ module.exports = function() { directory: bower.directory, // string or regexp to ignore from the injected filepath ignorePath: bower.ignorePath, + dependencies: true // default: true + }; + }; + + config.getWiredepKarmaOptions = function() { + return { + // The directory of your Bower packages. default: '.bowerrc'.directory || bower_components + bowerJson: bower.json, + // Your bower.json file contents. default: require('./bower.json') + directory: bower.directory, + // string or regexp to ignore from the injected filepath + ignorePath: bower.ignorePath, dependencies: true, // default: true - devDependencies: false, // default: false - includeSelf: false // default: false + devDependencies: true // default: false }; }; diff --git a/angularjs/showcase/gulpfile.js b/angularjs/showcase/gulpfile.js index d45633d..1a2f903 100644 --- a/angularjs/showcase/gulpfile.js +++ b/angularjs/showcase/gulpfile.js @@ -58,6 +58,23 @@ gulp.task('wiredep', function() { }); /** + * wire up bower dependencies and inject files in karma.conf.js + * + * @return {Stream} + */ +gulp.task('wiredepkarma', function() { + + log('Wiring bower dependencies into karma.conf.js'); + + var wiredep = require('wiredep').stream; + var jsFiles = args.stubs ? [].concat(config.jsFilesWithoutSpecs, config.jsFilesStubs) : config.jsFilesWithoutSpecs; + + return gulp.src(config.karmaConf) + .pipe(wiredep(config.getWiredepKarmaOptions())) + .pipe(gulp.dest(__dirname)); +}); + +/** * Runs HTTP server. */ gulp.task('server', ['wiredep'], function(done) { @@ -77,14 +94,14 @@ gulp.task('server', ['wiredep'], function(done) { * * @return {Stream} */ -gulp.task('test', ['vet'], function(done) { +gulp.task('test', ['vet', 'wiredepkarma'], function(done) { startTests(true, done); }); /** * Run specs and wait. Watch for file changes and re-run tests on each change */ -gulp.task('autotest', function(done) { +gulp.task('autotest', ['wiredepkarma'], function(done) { startTests(false, done); }); @@ -146,14 +163,15 @@ function server(environment) { */ function startTests(singleRun, done) { var excludeFiles = []; - var karma = require('karma').server; - - karma.start({ + var Server = require('karma').Server; + var karma = new Server({ configFile: __dirname + '/karma.conf.js', exclude: excludeFiles, singleRun: singleRun }, doneKarma); + karma.start(); + function doneKarma(result) { log('Karma completed'); log('Karma: tests exited with code ' + result); -- 2.1.4