From 4a5279ec1c86116dc5f592337248a608a6882f3a Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sat, 18 Jul 2015 08:47:47 -0400 Subject: [PATCH 01/14] Unit Testing: Initial Commit --- package.json | 2 +- .../app/src/app/components/heat/heat-route.js | 2 +- .../app/src/app/components/todo/todo-route.js | 2 +- test/default.spec.js | 26 ++++++++++++++++++- util.js | 13 ++++++++++ 5 files changed, 41 insertions(+), 4 deletions(-) mode change 100755 => 100644 package.json diff --git a/package.json b/package.json old mode 100755 new mode 100644 index b50a60e..4e9d214 --- a/package.json +++ b/package.json @@ -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", @@ -52,6 +51,7 @@ "yargs": "^3.7.2" }, "devDependencies": { + "assertthat": "^0.6.0", "chai": "*", "gulp-bump": "^0.3.0", "gulp-git": "^1.2.0", diff --git a/templates/app/src/app/components/heat/heat-route.js b/templates/app/src/app/components/heat/heat-route.js index 50b3dcb..8fa314f 100644 --- a/templates/app/src/app/components/heat/heat-route.js +++ b/templates/app/src/app/components/heat/heat-route.js @@ -12,7 +12,7 @@ $routeProvider .when('/heat', { controller: 'HeatCtrl', - templateUrl: '/view/heat.html', + templateUrl: '/components/view/heat.html', controllerAs: 'vm' }); } diff --git a/templates/app/src/app/components/todo/todo-route.js b/templates/app/src/app/components/todo/todo-route.js index 2990920..a14c9a0 100644 --- a/templates/app/src/app/components/todo/todo-route.js +++ b/templates/app/src/app/components/todo/todo-route.js @@ -11,7 +11,7 @@ $routeProvider .when('/todo', { controller: 'TodoCtrl', - templateUrl: '/todo.html' + templateUrl: '/components/todo.html' }); } diff --git a/test/default.spec.js b/test/default.spec.js index ff9753c..4ef64f8 100644 --- a/test/default.spec.js +++ b/test/default.spec.js @@ -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'); @@ -189,7 +191,29 @@ }); }); }); + ///////////// + 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(); + }); + }); + }); }); })(); diff --git a/util.js b/util.js index f45b9cc..71aba05 100644 --- a/util.js +++ b/util.js @@ -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'); From e1fe1d25e967e043bade58f4a903489ba9c72aaf Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sun, 19 Jul 2015 09:17:22 -0400 Subject: [PATCH 02/14] Unit Testing for controller added --- test/default.spec.js | 60 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/test/default.spec.js b/test/default.spec.js index 4ef64f8..d3555ee 100644 --- a/test/default.spec.js +++ b/test/default.spec.js @@ -191,22 +191,22 @@ }); }); }); - ///////////// - describe('constant generator', function () { - beforeEach(function() { + ///////////// Constants //////////// + describe('constant generator', function() { + beforeEach(function() { testingUtil.mockPrompt({ module: 'module1', - fileName : 'myconstant' + fileName: 'myconstant' }); util.setRuntimeMode('TEST'); }); - it('should put the constant file in the correct directory', function(done) { + 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) { + it('should put the correct constant filename', function(done) { gulp.start('constant').once('stop', function() { mockGulpDest.assertDestContains('myconstant-constant.js') done(); @@ -214,6 +214,54 @@ }); }); + ///////////// 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 }); })(); From 9e896712c532753c543edfb7b84105636045749c Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sun, 19 Jul 2015 09:22:30 -0400 Subject: [PATCH 03/14] Unittesting for decorator --- test/default.spec.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/default.spec.js b/test/default.spec.js index d3555ee..613a3c4 100644 --- a/test/default.spec.js +++ b/test/default.spec.js @@ -262,6 +262,29 @@ }); }); // With out test controller + describe('decorator generator test', function() { + beforeEach(function() { + testingUtil.mockPrompt({ + module: 'module1', + fileName: 'mydecorator', + test : false + }); + 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 }); })(); From 68e9d98c36e51f549cc7c2860d56d2cf1e5016ab Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sun, 19 Jul 2015 09:26:01 -0400 Subject: [PATCH 04/14] Unit testing for Directives added --- test/default.spec.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/test/default.spec.js b/test/default.spec.js index 613a3c4..2fc4a33 100644 --- a/test/default.spec.js +++ b/test/default.spec.js @@ -266,8 +266,7 @@ beforeEach(function() { testingUtil.mockPrompt({ module: 'module1', - fileName: 'mydecorator', - test : false + fileName: 'mydecorator' }); util.setRuntimeMode('TEST'); }); @@ -285,6 +284,28 @@ }); }); // 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 }); })(); From 873ea5354725e63ccbc13b5af5db91e04e668f56 Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sun, 19 Jul 2015 09:28:02 -0400 Subject: [PATCH 05/14] Unit testing for the factory test --- test/default.spec.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/default.spec.js b/test/default.spec.js index 2fc4a33..176510a 100644 --- a/test/default.spec.js +++ b/test/default.spec.js @@ -306,6 +306,28 @@ }); }); // 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 }); })(); From 59bcc9838a7f27631db6c9c643c388094cb534e9 Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sun, 19 Jul 2015 09:30:59 -0400 Subject: [PATCH 06/14] Unit Testing of filters added --- test/default.spec.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/default.spec.js b/test/default.spec.js index 176510a..c46c7d2 100644 --- a/test/default.spec.js +++ b/test/default.spec.js @@ -328,6 +328,28 @@ }); }); // 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 }); })(); From 2731bfde0988c2375dd80c695542ca88b79159a1 Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sun, 19 Jul 2015 09:53:44 -0400 Subject: [PATCH 07/14] Unit Testing for Module added --- test/default.spec.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/default.spec.js b/test/default.spec.js index c46c7d2..ea85329 100644 --- a/test/default.spec.js +++ b/test/default.spec.js @@ -350,6 +350,28 @@ }); }); // 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 }); })(); From 8416a2ad30e66d649b36d47710f716bdd55e8d14 Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sun, 19 Jul 2015 09:55:30 -0400 Subject: [PATCH 08/14] Unit testing module route testing added --- test/default.spec.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/default.spec.js b/test/default.spec.js index ea85329..1954b9a 100644 --- a/test/default.spec.js +++ b/test/default.spec.js @@ -372,6 +372,28 @@ }); }); // 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 }); })(); From a60d7eadbf68d563d3fce962793e38e71d31d140 Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sun, 19 Jul 2015 09:58:23 -0400 Subject: [PATCH 09/14] Unit testing for provider added --- test/default.spec.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/default.spec.js b/test/default.spec.js index 1954b9a..4b4d131 100644 --- a/test/default.spec.js +++ b/test/default.spec.js @@ -394,6 +394,28 @@ }); }); // 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 }); })(); From d157985b7c4e66867d3321b4ffa01631b35dfdf0 Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sun, 19 Jul 2015 10:01:20 -0400 Subject: [PATCH 10/14] Unit testing for Route added --- test/default.spec.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/default.spec.js b/test/default.spec.js index 4b4d131..0242408 100644 --- a/test/default.spec.js +++ b/test/default.spec.js @@ -416,6 +416,28 @@ }); }); // 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 }); })(); From 31fd1aebf5dc4bb1f38d2e7179e432fa1de60007 Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sun, 19 Jul 2015 10:02:29 -0400 Subject: [PATCH 11/14] Unit testing for service added --- test/default.spec.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/default.spec.js b/test/default.spec.js index 0242408..6979506 100644 --- a/test/default.spec.js +++ b/test/default.spec.js @@ -438,6 +438,28 @@ }); }); // 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 }); })(); From 2c2138bf988ab64ed295294b2ac8fb937b297978 Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sun, 19 Jul 2015 10:03:37 -0400 Subject: [PATCH 12/14] Unit testing for value added --- test/default.spec.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/default.spec.js b/test/default.spec.js index 6979506..f0e4a61 100644 --- a/test/default.spec.js +++ b/test/default.spec.js @@ -460,6 +460,28 @@ }); }); // 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 }); })(); From ce527366edcb17311ee62ae58598baabed4e217b Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sun, 19 Jul 2015 10:04:54 -0400 Subject: [PATCH 13/14] Added unit testing for view --- test/default.spec.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/default.spec.js b/test/default.spec.js index f0e4a61..687581f 100644 --- a/test/default.spec.js +++ b/test/default.spec.js @@ -482,6 +482,28 @@ }); }); // 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 }); })(); From 38c980dcfce5ba57733b6a84c8d5ae0766e761d4 Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sun, 19 Jul 2015 10:07:25 -0400 Subject: [PATCH 14/14] Addressed issue #5 on unit testing --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4e9d214..88bd9f5 100644 --- a/package.json +++ b/package.json @@ -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": {