diff --git a/demo/gulpfile.js b/demo/gulpfile.js index e646740..2efcb55 100644 --- a/demo/gulpfile.js +++ b/demo/gulpfile.js @@ -56,6 +56,22 @@ if(gutil.env.prod){ options.modulesData.karma.uses = 'karma' } +if(!gutil.env.demo){ + options.modulesData.unitTests = { + addDeps: [ + '../dist/utils.js', + '../specs/*.js', + '../node_modules/chalk/index.js' + // 'builds/dev/serve/app/**/variables.env.js' + ], + + excludeFiles: [ + 'builds/dev/serve/app/**/init.dev.env.js', + 'builds/dev/serve/app/**/init.prod.env.js' + ] + }; +} + /* ========================== Read gulp files diff --git a/dist/unit-tests.js b/dist/unit-tests.js index 3feea3b..0fb4bf2 100644 --- a/dist/unit-tests.js +++ b/dist/unit-tests.js @@ -12,45 +12,92 @@ module.exports = function(options) { var karma = require(options.modulesData['karma'].uses); var baseBuildUtils = require(options.modulesData['utils'].uses)(options); - function listFiles(callback) { + var wiredepOptions = _.extend({}, options.wiredep, { + dependencies: true, + devDependencies: true, + stream: null + }); + + var bowerDeps = wiredep(wiredepOptions); + var excludeFiles = options.modulesData['unitTests'].excludeFiles || []; + var additionalDeps = options.modulesData['unitTests'].addDeps || []; + var specFiles = options.specFiles || []; + var envFiles = { + all: options.tmp + '/serve/app/**/*.env.js', + dev: options.tmp + '/serve/app/**/*.dev.env.js', + prod: options.tmp + '/serve/app/**/*.prod.env.js', + found: [] + }; + + var htmlFiles = [ + options.src + '/**/*.html' + ]; + + var srcFiles = [ + options.tmp + '/serve/app/**/*.js' + ].concat(specFiles.map(function(file) { + return '!' + file; + })); + + srcFiles.unshift(envFiles.all); + + if($.util.env.prodTest){ + srcFiles = srcFiles.concat(options.modulesData.scripts.prodScripts); + } else { + srcFiles = srcFiles.concat(options.modulesData.scripts.devScripts); + } + console.log('srcFiles', srcFiles) - var wiredepOptions = _.extend({}, options.wiredep, { - dependencies: true, - devDependencies: true, - stream: null - }); + excludeFiles = excludeFiles.map(function(file) { + return '!' + file; + }); - var bowerDeps = wiredep(wiredepOptions); + srcFiles = srcFiles.concat(excludeFiles); - var additionalDeps = options.modulesData['unitTests'].addDeps || []; - var specFiles = options.specFiles || []; + function concatFilesToTest(files){ + var filesToTest = []; - var htmlFiles = [ - options.src + '/**/*.html' - ]; + filesToTest = filesToTest + .concat(bowerDeps.js) + .concat(additionalDeps) + .concat(files) + .concat(htmlFiles) + .concat(specFiles) + .concat(excludeFiles) - var srcFiles = [ - options.tmp + '/serve/app/**/*.js' - ].concat(specFiles.map(function(file) { - return '!' + file; - })); + return _.compact(filesToTest); + } - gulp.src(srcFiles) + function listFiles(callback) { + var filters = { + env : $.filter(envFiles.all), + src : $.filter(['**/*.js', '!**/*.env.js']) + }; + + var onConcatStream = function(files) { + var filesToTest = concatFilesToTest( _.pluck(files, 'path') ); + callback(filesToTest); + }; + + gulp.src( srcFiles ) + .pipe(filters.env) + .pipe($.angularFilesort()).on('error', options.errorHandler('AngularFilesort')) + .pipe(filters.env.restore()) + .pipe(filters.src) .pipe($.angularFilesort()).on('error', options.errorHandler('AngularFilesort')) - .pipe(concat(function(files) { - callback(bowerDeps.js - .concat(additionalDeps) - .concat(_.pluck(files, 'path')) - .concat(htmlFiles) - .concat(specFiles)); - })); + .pipe(filters.src.restore()) + .pipe(concat(onConcatStream)); + } + + function runKarmaServer(){ + } function runTests (testOptions, options) { - listFiles(function(files) { + var runKarmaServer = function(files) { var karmaModuleData = options.modulesData['karma']; var karmaConfFileName = process.cwd() + '/' + karmaModuleData.configFile; @@ -68,8 +115,17 @@ module.exports = function(options) { } server = new karma.Server(karmaOptions, function(){ testOptions.done() }); + + var errorHandler = options.errorHandler('Karma Server - Unit Tests'); + server.on('browser_error', function(browser, err){ + errorHandler(browser); + errorHandler(err); + }); server.start(); - }); + } + + listFiles(runKarmaServer); + } gulp.task('test', ['scripts'], function(done) {