Skip to content

Commit

Permalink
Merge pull request #17 from reflexdemon/unit-testing
Browse files Browse the repository at this point in the history
Unit testing
  • Loading branch information
reflexdemon committed Jul 19, 2015
2 parents 753af54 + 38c980d commit ae24e23
Show file tree
Hide file tree
Showing 5 changed files with 332 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package.json
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slush-angular-gulp",
"version": "0.3.1",
"version": "0.3.2",
"description": "Gulp, Angular, Less with Web server, this generator is build with inspiration from the below projects. slush-angular, angular-styleguide and generator-angular",
"main": "slushfile.js",
"repository": {
Expand Down Expand Up @@ -36,7 +36,6 @@
},
"homepage": "https://github.com/reflexdemon/slush-angular-gulp",
"dependencies": {
"assertthat": "^0.5.3",
"fs": "0.0.2",
"gulp": "^3.8.11",
"gulp-conflict": "^0.3.0",
Expand All @@ -52,6 +51,7 @@
"yargs": "^3.7.2"
},
"devDependencies": {
"assertthat": "^0.6.0",
"chai": "*",
"gulp-bump": "^0.3.0",
"gulp-git": "^1.2.0",
Expand Down
2 changes: 1 addition & 1 deletion templates/app/src/app/components/heat/heat-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$routeProvider
.when('/heat', {
controller: 'HeatCtrl',
templateUrl: '/view/heat.html',
templateUrl: '/components/view/heat.html',
controllerAs: 'vm'
});
}
Expand Down
2 changes: 1 addition & 1 deletion templates/app/src/app/components/todo/todo-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
$routeProvider
.when('/todo', {
controller: 'TodoCtrl',
templateUrl: '/todo.html'
templateUrl: '/components/todo.html'
});
}

Expand Down
316 changes: 315 additions & 1 deletion test/default.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
(function() {
'use strict';
var gulp = require('gulp'),
testingUtil = require('./testing_util.js'),
testingUtil = require('./testing_util'),
util = require('../util'),
_ = require('lodash'),
mockGulpDest = require('mock-gulp-dest')(gulp);

var assert = require('assertthat');
Expand Down Expand Up @@ -189,7 +191,319 @@
});
});
});
///////////// Constants ////////////
describe('constant generator', function() {
beforeEach(function() {
testingUtil.mockPrompt({
module: 'module1',
fileName: 'myconstant'
});
util.setRuntimeMode('TEST');
});
it('should put the constant file in the correct directory', function(done) {
gulp.start('constant').once('stop', function() {
assert.that(mockGulpDest.basePath()).is.endingWith('src/app/components/module1');
done();
});
});
it('should put the correct constant filename', function(done) {
gulp.start('constant').once('stop', function() {
mockGulpDest.assertDestContains('myconstant-constant.js')
done();
});
});

});
///////////// Controllers ////////////
describe('controller generator with test', function() {
beforeEach(function() {
testingUtil.mockPrompt({
module: 'module1',
fileName: 'mycontroller',
test : true
});
util.setRuntimeMode('TEST');
});
it('should put the controller file in the correct directory', function(done) {
gulp.start('controller').once('stop', function() {
assert.that(mockGulpDest.basePath()).is.endingWith('src/app/components/module1');
done();
});
});
it('should put the correct controller filename', function(done) {
gulp.start('controller').once('stop', function() {
mockGulpDest.assertDestContains('mycontroller-controller.js');
mockGulpDest.assertDestContains('mycontroller-controller.spec.js');
done();
});
});

}); // With test controller
describe('controller generator without test', function() {
beforeEach(function() {
testingUtil.mockPrompt({
module: 'module1',
fileName: 'mycontroller',
test : false
});
util.setRuntimeMode('TEST');
});
it('should put the controller file in the correct directory', function(done) {
gulp.start('controller').once('stop', function() {
assert.that(mockGulpDest.basePath()).is.endingWith('src/app/components/module1');
done();
});
});
it('should put the correct controller filename', function(done) {
gulp.start('controller').once('stop', function() {
mockGulpDest.assertDestContains('mycontroller-controller.js');
done();
});
});

}); // With out test controller
describe('decorator generator test', function() {
beforeEach(function() {
testingUtil.mockPrompt({
module: 'module1',
fileName: 'mydecorator'
});
util.setRuntimeMode('TEST');
});
it('should put the decorator file in the correct directory', function(done) {
gulp.start('decorator').once('stop', function() {
assert.that(mockGulpDest.basePath()).is.endingWith('src/app/components/module1');
done();
});
});
it('should put the correct decorator filename', function(done) {
gulp.start('decorator').once('stop', function() {
mockGulpDest.assertDestContains('mydecorator-decorator.js');
done();
});
});

}); // decorator test
describe('directive generator test', function() {
beforeEach(function() {
testingUtil.mockPrompt({
module: 'module1',
fileName: 'mydirective'
});
util.setRuntimeMode('TEST');
});
it('should put the directive file in the correct directory', function(done) {
gulp.start('directive').once('stop', function() {
assert.that(mockGulpDest.basePath()).is.endingWith('src/app/components/module1');
done();
});
});
it('should put the correct directive filename', function(done) {
gulp.start('directive').once('stop', function() {
mockGulpDest.assertDestContains('mydirective-directive.js');
done();
});
});

}); // directive test
describe('factory generator test', function() {
beforeEach(function() {
testingUtil.mockPrompt({
module: 'module1',
fileName: 'myfactory'
});
util.setRuntimeMode('TEST');
});
it('should put the factory file in the correct directory', function(done) {
gulp.start('factory').once('stop', function() {
assert.that(mockGulpDest.basePath()).is.endingWith('src/app/components/module1');
done();
});
});
it('should put the correct factory filename', function(done) {
gulp.start('factory').once('stop', function() {
mockGulpDest.assertDestContains('myfactory-factory.js');
done();
});
});

}); // factory test
describe('filter generator test', function() {
beforeEach(function() {
testingUtil.mockPrompt({
module: 'module1',
fileName: 'myfilter'
});
util.setRuntimeMode('TEST');
});
it('should put the filter file in the correct directory', function(done) {
gulp.start('filter').once('stop', function() {
assert.that(mockGulpDest.basePath()).is.endingWith('src/app/components/module1');
done();
});
});
it('should put the correct filter filename', function(done) {
gulp.start('filter').once('stop', function() {
mockGulpDest.assertDestContains('myfilter-filter.js');
done();
});
});

}); // filter test
describe('module - config generator test', function() {
beforeEach(function() {
testingUtil.mockPrompt({
module: 'mymodule',
config: 'config'
});
util.setRuntimeMode('TEST');
});
it('should put the module file in the correct directory', function(done) {
gulp.start('module').once('stop', function() {
assert.that(mockGulpDest.basePath()).is.endingWith('src/app/components/mymodule');
done();
});
});
it('should put the correct module filename', function(done) {
gulp.start('module').once('stop', function() {
mockGulpDest.assertDestContains('mymodule-config.js');
done();
});
});

}); // module test
describe('module - routes generator test', function() {
beforeEach(function() {
testingUtil.mockPrompt({
module: 'mymodule',
config: 'routes'
});
util.setRuntimeMode('TEST');
});
it('should put the module file in the correct directory', function(done) {
gulp.start('module').once('stop', function() {
assert.that(mockGulpDest.basePath()).is.endingWith('src/app/components/mymodule');
done();
});
});
it('should put the correct module filename', function(done) {
gulp.start('module').once('stop', function() {
mockGulpDest.assertDestContains('mymodule-routes.js');
done();
});
});

}); // module test
describe('provider generator test', function() {
beforeEach(function() {
testingUtil.mockPrompt({
module: 'module1',
fileName: 'myprovider'
});
util.setRuntimeMode('TEST');
});
it('should put the provider file in the correct directory', function(done) {
gulp.start('provider').once('stop', function() {
assert.that(mockGulpDest.basePath()).is.endingWith('src/app/components/module1');
done();
});
});
it('should put the correct provider filename', function(done) {
gulp.start('provider').once('stop', function() {
mockGulpDest.assertDestContains('myprovider-provider.js');
done();
});
});

}); // provider test
describe('route generator test', function() {
beforeEach(function() {
testingUtil.mockPrompt({
module: 'module1',
fileName: 'myroute'
});
util.setRuntimeMode('TEST');
});
it('should put the route file in the correct directory', function(done) {
gulp.start('route').once('stop', function() {
assert.that(mockGulpDest.basePath()).is.endingWith('src/app/components/module1');
done();
});
});
it('should put the correct route filename', function(done) {
gulp.start('route').once('stop', function() {
mockGulpDest.assertDestContains('myroute-route.js');
done();
});
});

}); // route test
describe('service generator test', function() {
beforeEach(function() {
testingUtil.mockPrompt({
module: 'module1',
fileName: 'myservice'
});
util.setRuntimeMode('TEST');
});
it('should put the service file in the correct directory', function(done) {
gulp.start('service').once('stop', function() {
assert.that(mockGulpDest.basePath()).is.endingWith('src/app/components/module1');
done();
});
});
it('should put the correct service filename', function(done) {
gulp.start('service').once('stop', function() {
mockGulpDest.assertDestContains('myservice-service.js');
done();
});
});

}); // service test
describe('value generator test', function() {
beforeEach(function() {
testingUtil.mockPrompt({
module: 'module1',
fileName: 'myvalue'
});
util.setRuntimeMode('TEST');
});
it('should put the value file in the correct directory', function(done) {
gulp.start('value').once('stop', function() {
assert.that(mockGulpDest.basePath()).is.endingWith('src/app/components/module1');
done();
});
});
it('should put the correct value filename', function(done) {
gulp.start('value').once('stop', function() {
mockGulpDest.assertDestContains('myvalue-value.js');
done();
});
});

}); // value test
describe('view generator test', function() {
beforeEach(function() {
testingUtil.mockPrompt({
module: 'module1',
fileName: 'myview'
});
util.setRuntimeMode('TEST');
});
it('should put the view file in the correct directory', function(done) {
gulp.start('view').once('stop', function() {
assert.that(mockGulpDest.basePath()).is.endingWith('src/app/components/module1');
done();
});
});
it('should put the correct view filename', function(done) {
gulp.start('view').once('stop', function() {
mockGulpDest.assertDestContains('myview-view.html');
done();
});
});

}); // view test
});

})();
13 changes: 13 additions & 0 deletions util.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,24 @@ module.exports.getDefaultOption = function(args, index) {
}
};

var runtimeMode ='LIVE';//Other option is 'TEST'
module.exports.setRuntimeMode = function(mode) {
runtimeMode = mode;
};

module.exports.getRuntimeMode = function() {
return runtimeMode;
};


/**
* Get Modules proposal
* @return {list} dir
*/
module.exports.getModuleProposal = function(appDir) {
if (runtimeMode === 'TEST') {
return ['module1', 'module2'];
}
var modules = [];
var componentsDir = appDir + '/components';
var fs = require('fs');
Expand Down

0 comments on commit ae24e23

Please sign in to comment.