Skip to content

Commit

Permalink
Merge pull request linnovate#1560 from pashist/master
Browse files Browse the repository at this point in the history
Update test configuration
  • Loading branch information
liorkesos committed May 8, 2016
2 parents 6b83201 + 547009e commit 5fb5f0a
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 804 deletions.
87 changes: 7 additions & 80 deletions gulp/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,9 @@ var plugins = gulpLoadPlugins();

process.env.NODE_ENV = 'test';

function processIncludes(aggregatedAssets) {

// Process all node_modules, find mean packages, and map directory names
var dirmap = [];
var nodemods = __dirname + '/../node_modules';
fs.readdirSync(nodemods).forEach(function(file) {
try {
var data = fs.readFileSync(path.join(nodemods, file, 'mean.json'));
if (data) {
var json = JSON.parse(data.toString());
if (json.name) {
dirmap[file] = json.name;
}
}
} catch (e) {
// not a file
}
});

for(var i = 0; i < aggregatedAssets.length; ++i) {
aggregatedAssets[i] = aggregatedAssets[i].slice(1);
if(aggregatedAssets[i].indexOf('bower_components/') === -1) {
var index = aggregatedAssets[i].indexOf('/') + 1;
var packageName = aggregatedAssets[i].substring(0, index-1);
var nmIndex = -1;
for(var dirName in dirmap) {
if(dirmap[dirName] === packageName) {
nmIndex = dirName;
break;
}
}
if(nmIndex === -1) {
aggregatedAssets[i] = aggregatedAssets[i].substring(0, index) + 'public/' + aggregatedAssets[i].substring(index);
} else {
aggregatedAssets[i] = 'node_modules/' + nmIndex + '/public/' + aggregatedAssets[i].substring(index);
}
}
try {
fs.lstatSync(__dirname + '/../packages/core/' + aggregatedAssets[i]);
aggregatedAssets[i] = 'packages/core/' + aggregatedAssets[i];
continue;
} catch(e) {
// Not a file
}
try {
fs.lstatSync(__dirname + '/../packages/custom/' + aggregatedAssets[i]);
aggregatedAssets[i] = 'packages/custom/' + aggregatedAssets[i];
} catch (e) {
// Not a file
}
}
return aggregatedAssets;
}

gulp.task('test', ['startServer', 'stopServer']);
gulp.task('startServer', function(done) {
var promise = require('../server.js');

promise.then(function(app){done();});
});
gulp.task('stopServer', ['runKarma'], function() {
Expand All @@ -85,31 +30,13 @@ gulp.task('runMocha', ['startServer'], function () {
});
});
gulp.task('runKarma', ['runMocha'], function (done) {
request('http://localhost:3001/api/aggregatedassets', function(error, response, body) {
var aggregatedassets = JSON.parse(body);
aggregatedassets = processIncludes(aggregatedassets.footer.js);

var karma = new KarmaServer({
configFile: __dirname + '/../karma.conf.js',
singleRun: true,
files: aggregatedassets.concat(['packages/**/public/tests/**/*.js', 'packages/**/public/**/*.html'])
}, function () {
done();
});

karma.start();
var karma = new KarmaServer({
configFile: __dirname + '/../karma.conf.js',
singleRun: true
}, function () {
done();
});
});

// function mapFile(dirmap, promise, file, err, data) {
// if(!err) {
// var json = JSON.parse(data.toString());
// if(json.name) {
// dirmap[file] = json.name;
// }
// promise.resolve();
// }
// else {
// promise.resolve();
// }
// }
karma.start();
});
30 changes: 25 additions & 5 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ module.exports = function(config) {
basePath: basePath,

// frameworks to use
frameworks: ['jasmine', 'phantomjs-shim'],

frameworks: ['jasmine'],
files: [
'app.js',
'packages/**/public/tests/**/*.js'
],
// list of files to exclude
exclude: [],

Expand All @@ -32,7 +35,15 @@ module.exports = function(config) {
'packages/**/public/services/**/*.js': ['coverage'],
'packages/**/public/directives/**/*.js': ['coverage'],

'packages/**/public/**/*.html': ['ng-html2js']
'packages/**/public/**/*.html': ['ng-html2js'],

// 'packages/**/public/tests/**/*.js': ['webpack', 'babel'],
'app.js': ['webpack']
},

webpack: require('./webpack.test.js'),
webpackMiddleware: {
noInfo:true
},

coverageReporter: {
Expand Down Expand Up @@ -81,9 +92,18 @@ module.exports = function(config) {

// If browser does not capture in given timeout [ms], kill it
captureTimeout: 60000,

// How long will Karma wait for a message from a browser before disconnecting from it (in ms).
browserNoActivityTimeout: 60000,
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: true
singleRun: true,
plugins: [
'karma-jasmine',
'karma-webpack',
'karma-ng-html2js-preprocessor',
'karma-phantomjs-launcher',
'karma-coverage',
'karma-junit-reporter'
]
});
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"postinstall": "node tools/scripts/postinstall.js"
},
"dependencies": {
"angular": "^1.5.5",
"angular-bootstrap": "^0.12.2",
"angular-cookies": "^1.5.2",
"angular-jwt": "latest",
Expand Down Expand Up @@ -90,6 +91,7 @@
"karma-phantomjs-shim": "latest",
"karma-requirejs": "latest",
"karma-script-launcher": "latest",
"karma-webpack": "^1.7.0",
"mocha": "latest",
"phantomjs-prebuilt": "latest",
"protractor": "latest",
Expand Down
Loading

0 comments on commit 5fb5f0a

Please sign in to comment.