Skip to content

Commit

Permalink
remove aggregation from tests
Browse files Browse the repository at this point in the history
updated karma.conf.js to working with webpack
added example of test ro meanStarter package
  • Loading branch information
pavel committed May 6, 2016
1 parent 8d1f97e commit 5d40b6c
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 88 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();
});
28 changes: 23 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,16 @@ module.exports = function(config) {

// If browser does not capture in given timeout [ms], kill it
captureTimeout: 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
12 changes: 12 additions & 0 deletions packages/custom/meanStarter/public/tests/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
describe('StarterController', function() {
var controller, scope;
beforeEach(module('mean.meanStarter'));
beforeEach(inject(function($controller, $rootScope){
scope = $rootScope.$new();
controller = $controller('StarterController', { $scope: scope });
}));

it('package object in scope should contain proper package name', function() {
expect(scope.package.name).toEqual('meanStarter');
});
});
4 changes: 1 addition & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ var path = require('path');

module.exports = {
context: __dirname,
entry: {
app: ['./app.js']
},
entry: './app.js',
output: {
path: path.join(__dirname, './bundle'),
publicPath: '/',
Expand Down
21 changes: 21 additions & 0 deletions webpack.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

module.exports = {
module: {
loaders: [
{test: /\.css$/, loader: 'style-loader!css-loader'},
{
test: /\.js$/,
exclude: /(node_modules|bower_components|lib)/,
loader: 'babel?presets[]=es2015&presets[]=stage-1'
},
{
test: /(.*)\.(eot|svg|ttf|woff|woff2)$/,
loader: 'url-loader'
}
]
},
resolve: {
modulesDirectories: ['bower_components', 'node_modules']
}
};

0 comments on commit 5d40b6c

Please sign in to comment.