From: Gustavo Martin Morcuende Date: Thu, 27 Aug 2015 19:34:52 +0000 (+0200) Subject: gulp-my-tasks: when injecting stubs into index.html we will also inject angular... X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=6582d76d6dfc9a2bbe59763f9ff7c2bc900ae2fc;p=JavaScriptForFun gulp-my-tasks: when injecting stubs into index.html we will also inject angular-mock * angular-mock enables us to use ngMockE2E * karma.conf.js requires $templateProvider. It is useful when templates in directives are located in html files instead of right in the code. We could also use karma-ng-html2js-preprocessor but in my case i don't need it because I am already generating my templates :) --- diff --git a/angularjs/showcase/karma.conf.js b/angularjs/showcase/karma.conf.js index 7adcd44..a635bb4 100644 --- a/angularjs/showcase/karma.conf.js +++ b/angularjs/showcase/karma.conf.js @@ -32,7 +32,8 @@ module.exports = function(config) { 'bower_components/angular-mocks/angular-mocks.js', //endbower 'src/showcase/app/**/*.module.js', - 'src/showcase/app/**/*.js' + 'src/showcase/app/**/*.js', + '.tmp/templates.js' ], // list of files / patterns to exclude diff --git a/gulp/gulp-my-tasks/tasks/tasks.config.js b/gulp/gulp-my-tasks/tasks/tasks.config.js index 033ebb1..c578b19 100644 --- a/gulp/gulp-my-tasks/tasks/tasks.config.js +++ b/gulp/gulp-my-tasks/tasks/tasks.config.js @@ -72,41 +72,6 @@ module.exports = function() { } return options; - }, - - /** - * wiredep options for karma.conf.js - */ - wiredepKarmaOptions: function(isVerbose) { - var options = { - // 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: true, // default: false - }; - - if (isVerbose) { - options.onError = function (err) { - console.log('wiredep error: ' + err.code); - }; - options.onFileUpdated = function (filePath) { - console.log('wiredep updated file: ' + filePath); - }; - options.onPathInjected = function (fileObject) { - console.log('wiredep injected file: ' + fileObject.block); - console.log('wiredep injected file: ' + fileObject.file); - console.log('wiredep injected file: ' + fileObject.path); - }; - options.onMainNotFound = function (pkg) { - console.log('wiredep name of bower package without main: ' + pkg); - } - } - - return options; } }; diff --git a/gulp/gulp-my-tasks/tasks/tasks.js b/gulp/gulp-my-tasks/tasks/tasks.js index 4f254bb..1021010 100644 --- a/gulp/gulp-my-tasks/tasks/tasks.js +++ b/gulp/gulp-my-tasks/tasks/tasks.js @@ -97,10 +97,16 @@ module.exports = function(gulp, customConfig) { log('*** Wiring bower dependencies and injecting files into html ***'); var wiredep = require('wiredep').stream; - var jsFiles = args.stubs ? [].concat(config.jsFilesWithoutSpecs, config.jsFilesStubs) : config.jsFilesWithoutSpecs; + var jsFiles = config.jsFilesWithoutSpecs; + var options = config.wiredepOptions(args.verbose ? true : false); + + if (args.stubs) { + jsFiles = [].concat(config.jsFilesWithoutSpecs, config.jsFilesStubs); + options.devDependencies = true; + } return gulp.src(config.index) - .pipe(wiredep(config.wiredepOptions(args.verbose ? true : false))) + .pipe(wiredep(options)) .pipe(inject(jsFiles, '')) .pipe(gulp.dest(config.main)); }); @@ -118,9 +124,11 @@ module.exports = function(gulp, customConfig) { log('*** Wiring bower dependencies into karma.conf.js ***'); var wiredep = require('wiredep').stream; + var options = config.wiredepOptions(args.verbose ? true : false); + options.devDependencies = true; return gulp.src(config.karmaConf) - .pipe(wiredep(config.wiredepKarmaOptions(args.verbose ? true : false))) + .pipe(wiredep(options)) .pipe(gulp.dest(currentDir)); }); @@ -151,7 +159,7 @@ module.exports = function(gulp, customConfig) { * * @returns {Stream} */ - gulp.task('test', ['vet', 'wireupkarma'], function(done) { + gulp.task('test', ['vet', 'wireupkarma', 'templatecache'], function(done) { log('*** Run tests once ***'); @@ -164,7 +172,7 @@ module.exports = function(gulp, customConfig) { * @description * Run specs and wait. Watch for file changes and re-run tests on each change */ - gulp.task('autotest', ['wireupkarma'], function(done) { + gulp.task('autotest', ['wireupkarma', 'templatecache'], function(done) { log('*** Run tests and wait ***');