Skip to content

Commit

Permalink
Close #17 - Fix env injector on specs
Browse files Browse the repository at this point in the history
  • Loading branch information
carloshpds committed Dec 25, 2015
1 parent 8aed622 commit 0c5b122
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 27 deletions.
16 changes: 16 additions & 0 deletions demo/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
110 changes: 83 additions & 27 deletions dist/unit-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit 0c5b122

Please sign in to comment.