From a583cf212bf9ebe0f1b0b97b2ba4b5843d4b48f8 Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Mon, 20 Jul 2015 07:57:13 -0400 Subject: [PATCH 1/8] Modularizing the unit tests --- test/app/app.spec.js | 85 +++++++++++++++++++++++++ test/common.js | 28 ++++++++ test/constant/constant.spec.js | 26 ++++++++ test/controller/controller.test.spec.js | 25 ++++++++ test/top.js | 54 ++++++++++++++++ 5 files changed, 218 insertions(+) create mode 100644 test/app/app.spec.js create mode 100644 test/common.js create mode 100644 test/constant/constant.spec.js create mode 100644 test/controller/controller.test.spec.js create mode 100644 test/top.js diff --git a/test/app/app.spec.js b/test/app/app.spec.js new file mode 100644 index 0000000..49c28b1 --- /dev/null +++ b/test/app/app.spec.js @@ -0,0 +1,85 @@ +(function() { + 'use strict'; + + var common = require("../common"); + var options = common.options; + var assert = common.assert; + var testingUtil = common.testingUtil; + var mockGulpDest = common.mockGulpDest; + var gulp = common.gulp; + + + + + it('should put all project files in current working directory', function(done) { + gulp.start('default').once('stop', function() { + // mockGulpDest.cwd().should.equal(__dirname); + // mockGulpDest.basePath().should.equal(__dirname); + + assert.that(mockGulpDest.cwd() + '/app').is.equalTo(__dirname); + assert.that(mockGulpDest.basePath() + '/app').is.equalTo(__dirname); + done(); + }); + }); + it('should add dot files to project root', function(done) { + gulp.start('default').once('stop', function() { + mockGulpDest.assertDestContains([ + '.bowerrc', + '.csslintrc', + '.editorconfig', + '.gitignore', + '.jshintrc' + ]); + done(); + }); + }); + it('should add bower.json and package.json to project root', function(done) { + gulp.start('default').once('stop', function() { + mockGulpDest.assertDestContains([ + 'package.json', + 'bower.json' + ]); + done(); + }); + }); + it('should add a gulpfile to project root', function(done) { + gulp.start('default').once('stop', function() { + mockGulpDest.assertDestContains('gulpfile.js'); + done(); + }); + }); + it('should add a karma config file to project root', function(done) { + gulp.start('default').once('stop', function() { + mockGulpDest.assertDestContains('karma.conf.js'); + done(); + }); + }); + it('should add a readme file to project root', function(done) { + gulp.start('default').once('stop', function() { + mockGulpDest.assertDestContains('README.md'); + done(); + }); + }); + it('should add an index.html to the app folder', function(done) { + gulp.start('default').once('stop', function() { + mockGulpDest.assertDestContains('src/app/index.html'); + done(); + }); + }); + it('should add a JavaScript app module definition file by default', function(done) { + testingUtil.mockPrompt({ + name: 'module' + }); + gulp.start('default').once('stop', function() { + mockGulpDest.assertDestContains('src/app/app.js'); + done(); + }); + }); + it('should create a gitkeep file in the app assets dir', function(done) { + gulp.start('default').once('stop', function() { + mockGulpDest.assertDestContains('src/app/assets/.gitkeep'); + done(); + }); + }); + +})(); diff --git a/test/common.js b/test/common.js new file mode 100644 index 0000000..7abfe87 --- /dev/null +++ b/test/common.js @@ -0,0 +1,28 @@ +(function() { + 'use strict'; + var chai = require("chai"); + + var gulp = require('gulp'), + testingUtil = require('./testing_util'), + util = require('../util'), + _ = require('lodash'), + mockGulpDest = require('mock-gulp-dest')(gulp); + + var assert = require('assertthat') + + var options = { + runtime : 'TEST' + }; + + + exports._ = _; + exports.assert = assert; + exports.chai = chai; + exports.gulp = gulp; + exports.mockGulpDest = mockGulpDest; + exports.testingUtil = testingUtil; + exports.util = util; + + exports.options = options; + +})(); diff --git a/test/constant/constant.spec.js b/test/constant/constant.spec.js new file mode 100644 index 0000000..493c95c --- /dev/null +++ b/test/constant/constant.spec.js @@ -0,0 +1,26 @@ +(function() { + 'use strict'; + + var common = require("../common"); + var options = common.options; + var assert = common.assert; + var testingUtil = common.testingUtil; + var mockGulpDest = common.mockGulpDest; + var gulp = common.gulp; + + 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() { + console.log('mockGulpDest.files', mockGulpDest.files()); + mockGulpDest.assertDestContains('myfilename-constant.js') + done(); + }); + }); + +})(); + diff --git a/test/controller/controller.test.spec.js b/test/controller/controller.test.spec.js new file mode 100644 index 0000000..96acfd1 --- /dev/null +++ b/test/controller/controller.test.spec.js @@ -0,0 +1,25 @@ +(function() { + 'use strict'; + + var common = require("../common"); + var options = common.options; + var assert = common.assert; + var testingUtil = common.testingUtil; + var mockGulpDest = common.mockGulpDest; + var gulp = common.gulp; + + 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('myfilename-controller.js'); + mockGulpDest.assertDestContains('myfilename-controller.spec.js'); + done(); + }); + }); + +})(); diff --git a/test/top.js b/test/top.js new file mode 100644 index 0000000..bb54661 --- /dev/null +++ b/test/top.js @@ -0,0 +1,54 @@ +(function() { + 'use strict'; + + function importTest(name, path) { + describe(name, function() { + require(path); + }); + } + + var common = require("./common"); + var testingUtil = common.testingUtil; + var util = common.util; + var _ = common._; + + var testSuite = [{ + description: 'Test the Application generator', + testcase: './app/app.spec' + }, { + description: 'Test the Constants generator', + testcase: './constant/constant.spec' + }, { + description: 'Test controller generator with test', + testcase: './controller/controller.test.spec' + }]; + + //Load the main slush file for testing + require('../slushfile'); + + describe('slush-angular-gulp', function() { + before(function() { + process.chdir(__dirname); + }); + + function beforeEach() { + testingUtil.mockPrompt({ + name: 'module', + example: ['todo'], + module: 'module1', + fileName: 'myfilename', + test: true + }); + util.setRuntimeMode('TEST'); + } + _.each(testSuite, function(tCase) { + importTest(tCase.description, tCase.testcase); + }); + + + after(function() { + console.log('Completed.'); + }); + }); + +})(); From 58530b16034f197a9b094c21e21e0894f114e258 Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sat, 1 Aug 2015 10:24:04 -0400 Subject: [PATCH 2/8] Moved the files to better location --- test/{app => cases}/app.spec.js | 0 test/{constant => cases}/constant.spec.js | 0 test/{controller => cases}/controller.test.spec.js | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename test/{app => cases}/app.spec.js (100%) rename test/{constant => cases}/constant.spec.js (100%) rename test/{controller => cases}/controller.test.spec.js (100%) diff --git a/test/app/app.spec.js b/test/cases/app.spec.js similarity index 100% rename from test/app/app.spec.js rename to test/cases/app.spec.js diff --git a/test/constant/constant.spec.js b/test/cases/constant.spec.js similarity index 100% rename from test/constant/constant.spec.js rename to test/cases/constant.spec.js diff --git a/test/controller/controller.test.spec.js b/test/cases/controller.test.spec.js similarity index 100% rename from test/controller/controller.test.spec.js rename to test/cases/controller.test.spec.js From eba64ba6fdf7647551e0d92093f50bb1ec80e2fe Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sat, 1 Aug 2015 10:56:40 -0400 Subject: [PATCH 3/8] Making good progress in running NPM tests --- package.json | 2 ++ test/cases/app.spec.js | 21 +++++++++++++++++++-- test/cases/constant.spec.js | 16 +++++++++++++--- test/cases/controller.test.spec.js | 17 +++++++++++++++-- test/top.js | 19 +++++++++++++------ 5 files changed, 62 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index f43d2d7..3d4227f 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,8 @@ "scripts": { "test": "NODE_ENV=test mocha -R spec test/*.spec.js", "posttest": "NODE_ENV=test mocha -R travis-cov test/*.spec.js", + "modular": "NODE_ENV=test mocha -R spec test/top.js", + "travis": "NODE_ENV=test mocha -R travis-cov test/top.js", "coveralls": "NODE_ENV=test ./node_modules/.bin/mocha test/*.spec.js -R mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js" }, "config": { diff --git a/test/cases/app.spec.js b/test/cases/app.spec.js index 49c28b1..017d7e0 100644 --- a/test/cases/app.spec.js +++ b/test/cases/app.spec.js @@ -5,23 +5,33 @@ var options = common.options; var assert = common.assert; var testingUtil = common.testingUtil; + var util = common.util; var mockGulpDest = common.mockGulpDest; var gulp = common.gulp; + function beforeEach() { + process.chdir(__dirname); + testingUtil.mockPrompt({ + name: 'module' + }); + util.setRuntimeMode('TEST'); + } it('should put all project files in current working directory', function(done) { + beforeEach(); gulp.start('default').once('stop', function() { // mockGulpDest.cwd().should.equal(__dirname); // mockGulpDest.basePath().should.equal(__dirname); - assert.that(mockGulpDest.cwd() + '/app').is.equalTo(__dirname); - assert.that(mockGulpDest.basePath() + '/app').is.equalTo(__dirname); + assert.that(mockGulpDest.cwd()).is.equalTo(__dirname); + assert.that(mockGulpDest.basePath()).is.equalTo(__dirname); done(); }); }); it('should add dot files to project root', function(done) { + beforeEach(); gulp.start('default').once('stop', function() { mockGulpDest.assertDestContains([ '.bowerrc', @@ -34,6 +44,7 @@ }); }); it('should add bower.json and package.json to project root', function(done) { + beforeEach(); gulp.start('default').once('stop', function() { mockGulpDest.assertDestContains([ 'package.json', @@ -43,24 +54,28 @@ }); }); it('should add a gulpfile to project root', function(done) { + beforeEach(); gulp.start('default').once('stop', function() { mockGulpDest.assertDestContains('gulpfile.js'); done(); }); }); it('should add a karma config file to project root', function(done) { + beforeEach(); gulp.start('default').once('stop', function() { mockGulpDest.assertDestContains('karma.conf.js'); done(); }); }); it('should add a readme file to project root', function(done) { + beforeEach(); gulp.start('default').once('stop', function() { mockGulpDest.assertDestContains('README.md'); done(); }); }); it('should add an index.html to the app folder', function(done) { + beforeEach(); gulp.start('default').once('stop', function() { mockGulpDest.assertDestContains('src/app/index.html'); done(); @@ -70,12 +85,14 @@ testingUtil.mockPrompt({ name: 'module' }); + beforeEach(); gulp.start('default').once('stop', function() { mockGulpDest.assertDestContains('src/app/app.js'); done(); }); }); it('should create a gitkeep file in the app assets dir', function(done) { + beforeEach(); gulp.start('default').once('stop', function() { mockGulpDest.assertDestContains('src/app/assets/.gitkeep'); done(); diff --git a/test/cases/constant.spec.js b/test/cases/constant.spec.js index 493c95c..1a9b4ba 100644 --- a/test/cases/constant.spec.js +++ b/test/cases/constant.spec.js @@ -5,22 +5,32 @@ var options = common.options; var assert = common.assert; var testingUtil = common.testingUtil; + var util = common.util; var mockGulpDest = common.mockGulpDest; var gulp = common.gulp; + function beforeEach() { + process.chdir(__dirname); + testingUtil.mockPrompt({ + module: 'module1', + fileName: 'myconstant' + }); + util.setRuntimeMode('TEST'); + } + it('should put the constant file in the correct directory', function(done) { + beforeEach(); 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) { + beforeEach(); gulp.start('constant').once('stop', function() { - console.log('mockGulpDest.files', mockGulpDest.files()); - mockGulpDest.assertDestContains('myfilename-constant.js') + mockGulpDest.assertDestContains('myconstant-constant.js') done(); }); }); })(); - diff --git a/test/cases/controller.test.spec.js b/test/cases/controller.test.spec.js index 96acfd1..4efba06 100644 --- a/test/cases/controller.test.spec.js +++ b/test/cases/controller.test.spec.js @@ -5,19 +5,32 @@ var options = common.options; var assert = common.assert; var testingUtil = common.testingUtil; + var util = common.util; var mockGulpDest = common.mockGulpDest; var gulp = common.gulp; + function beforeEach() { + process.chdir(__dirname); + testingUtil.mockPrompt({ + module: 'module1', + fileName: 'mycontroller', + test: true + }); + util.setRuntimeMode('TEST'); + } + it('should put the controller file in the correct directory', function(done) { + beforeEach(); 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) { + beforeEach(); gulp.start('controller').once('stop', function() { - mockGulpDest.assertDestContains('myfilename-controller.js'); - mockGulpDest.assertDestContains('myfilename-controller.spec.js'); + mockGulpDest.assertDestContains('mycontroller-controller.js'); + mockGulpDest.assertDestContains('mycontroller-controller.spec.js'); done(); }); }); diff --git a/test/top.js b/test/top.js index bb54661..fa429fc 100644 --- a/test/top.js +++ b/test/top.js @@ -14,24 +14,31 @@ var testSuite = [{ description: 'Test the Application generator', - testcase: './app/app.spec' + testcase: './cases/app.spec' }, { description: 'Test the Constants generator', - testcase: './constant/constant.spec' + testcase: './cases/constant.spec' }, { description: 'Test controller generator with test', - testcase: './controller/controller.test.spec' + testcase: './cases/controller.test.spec' }]; + require('blanket')({ + pattern: function(filename) { + return !/node_modules/.test(filename); + } + }); + //Load the main slush file for testing require('../slushfile'); describe('slush-angular-gulp', function() { - before(function() { - process.chdir(__dirname); - }); + // before(function() { + // process.chdir(__dirname); + // }); function beforeEach() { + process.chdir(__dirname); testingUtil.mockPrompt({ name: 'module', example: ['todo'], From b43acaf41311fd7adf7e61bab019b38c4b57ec63 Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sat, 1 Aug 2015 11:30:22 -0400 Subject: [PATCH 4/8] Fixed a strange behaviour with Controller --- tasks/controller.js | 127 +++++++++++++++++------------ test/cases/controller.test.spec.js | 13 ++- 2 files changed, 82 insertions(+), 58 deletions(-) diff --git a/tasks/controller.js b/tasks/controller.js index 0d452f9..a923e49 100644 --- a/tasks/controller.js +++ b/tasks/controller.js @@ -4,68 +4,87 @@ */ (function() { -var gulp = require('gulp'), - install = require('gulp-install'), - conflict = require('gulp-conflict'), - template = require('gulp-template'), - rename = require('gulp-rename'), - inquirer = require('inquirer') + var gulp = require('gulp'), + install = require('gulp-install'), + conflict = require('gulp-conflict'), + template = require('gulp-template'), + rename = require('gulp-rename'), + inquirer = require('inquirer') _ = require('underscore.string'); -//Local dependencies -var util = require('../util'); + //Local dependencies + var util = require('../util'); -module.exports = function(gulp) { - 'use strict'; + module.exports = function(gulp) { + 'use strict'; - gulp.task('controller', function(done) { - var _this = this; - var name = util.getDefaultOption(_this.args, 0); - var options = util.getGlobalOptions(); - var modules = util.getModuleProposal(options.appDir); + gulp.task('controller', function(done) { + var _this = this; + var name = util.getDefaultOption(_this.args, 0); + var options = util.getGlobalOptions(); + var modules = util.getModuleProposal(options.appDir); - if (modules.length === 0) { - throw new Error('Controller must be created in a module, but no modules exist. Create a module using "slush angular-gulp:module ".'); - } + if (modules.length === 0) { + throw new Error('Controller must be created in a module, but no modules exist. Create a module using "slush angular-gulp:module ".'); + } + + inquirer.prompt([{ + type: 'input', + name: 'fileName', + message: 'What is the name of your controller?' + }, { + type: 'list', + name: 'module', + message: 'What is your AngularJS module name?', + choices: modules + }, { + type: 'confirm', + name: 'spec', + message: 'Do you want to include unit testing?', + default: true + }], function(answers) { + //Init + answers.nameDashed = _.slugify(util.getNameProposal()); + answers.scriptAppName = _.camelize(answers.nameDashed) + '.' + answers.module; + answers.classedName = _.capitalize(_.camelize(answers.fileName)); + // console.log('answers:', answers); + // test + if (answers.spec === true) { + gulp.src(__dirname + '/../templates/controller/controller.spec.js') + .pipe(template(answers)) + .pipe(rename(answers.fileName + '-controller.spec.js')) + .pipe(conflict(options.base + options.appDir + '/components/' + answers.module)) + .pipe(gulp.dest(options.base + options.appDir + '/components/' + answers.module)); + gulp.src(__dirname + '/../templates/controller/controller.js') + .pipe(template(answers)) + .pipe(rename(answers.fileName + '-controller.js')) + .pipe(conflict(options.base + options.appDir + '/components/' + answers.module)) + .pipe(gulp.dest(options.base + options.appDir + '/components/' + answers.module)) + .on('finish', function() { + done(); + }); - inquirer.prompt([{ - type: 'input', - name: 'fileName', - message: 'What is the name of your controller?', - default: name - }, { - type: 'list', - name: 'module', - message: 'What is your AngularJS module name?', - choices: modules - }, { - type: 'confirm', - name: 'test', - message: 'Do you want to include unit testing?', - default: true - }], function(answers) { - //Init - answers.nameDashed = _.slugify(util.getNameProposal()); - answers.scriptAppName = _.camelize(answers.nameDashed) + '.' +answers.module ; - answers.classedName = _.capitalize(_.camelize(answers.fileName)); - // test - if (answers.test) { - gulp.src(__dirname + '/../templates/controller/controller.spec.js') + } else { + gulp.src(__dirname + '/../templates/controller/controller.js') + .pipe(template(answers)) + .pipe(rename(answers.fileName + '-controller.js')) + .pipe(conflict(options.base + options.appDir + '/components/' + answers.module)) + .pipe(gulp.dest(options.base + options.appDir + '/components/' + answers.module)) + .on('finish', function() { + done(); + }); + + } + //Source + gulp.src(__dirname + '/../templates/controller/controller.js') .pipe(template(answers)) - .pipe(rename(answers.fileName + '-controller.spec.js')) + .pipe(rename(answers.fileName + '-controller.js')) .pipe(conflict(options.base + options.appDir + '/components/' + answers.module)) .pipe(gulp.dest(options.base + options.appDir + '/components/' + answers.module)) - } - //Source - gulp.src(__dirname + '/../templates/controller/controller.js') - .pipe(template(answers)) - .pipe(rename(answers.fileName + '-controller.js')) - .pipe(conflict(options.base + options.appDir + '/components/' + answers.module)) - .pipe(gulp.dest(options.base + options.appDir + '/components/' + answers.module)) - .on('finish', function() { - done(); - }); + .on('finish', function() { + done(); + }); + }); }); - }); -} + } })(); diff --git a/test/cases/controller.test.spec.js b/test/cases/controller.test.spec.js index 4efba06..bae2baf 100644 --- a/test/cases/controller.test.spec.js +++ b/test/cases/controller.test.spec.js @@ -6,6 +6,7 @@ var assert = common.assert; var testingUtil = common.testingUtil; var util = common.util; + var _ = common._; var mockGulpDest = common.mockGulpDest; var gulp = common.gulp; @@ -13,8 +14,8 @@ process.chdir(__dirname); testingUtil.mockPrompt({ module: 'module1', - fileName: 'mycontroller', - test: true + fileName: 'default', + spec: true }); util.setRuntimeMode('TEST'); } @@ -29,8 +30,12 @@ it('should put the correct controller filename', function(done) { beforeEach(); gulp.start('controller').once('stop', function() { - mockGulpDest.assertDestContains('mycontroller-controller.js'); - mockGulpDest.assertDestContains('mycontroller-controller.spec.js'); + var files = []; + // _.each(mockGulpDest.files(), function (item) { + // console.log('mockGulpDest', item); + // }); + mockGulpDest.assertDestContains('default-controller.js'); + mockGulpDest.assertDestContains('default-controller.spec.js'); done(); }); }); From faf09d6134dca259cbca29ec9fe32c0387e60a7a Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sat, 1 Aug 2015 17:10:29 -0400 Subject: [PATCH 5/8] Logaccly completed half of the testcases 36/55 --- tasks/controller.js | 18 +++++++++--------- test/cases/controller.test.spec.js | 6 +++--- test/top.js | 21 +++++++++++++++++++++ 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/tasks/controller.js b/tasks/controller.js index a923e49..8e4bd95 100644 --- a/tasks/controller.js +++ b/tasks/controller.js @@ -75,15 +75,15 @@ }); } - //Source - gulp.src(__dirname + '/../templates/controller/controller.js') - .pipe(template(answers)) - .pipe(rename(answers.fileName + '-controller.js')) - .pipe(conflict(options.base + options.appDir + '/components/' + answers.module)) - .pipe(gulp.dest(options.base + options.appDir + '/components/' + answers.module)) - .on('finish', function() { - done(); - }); + // //Source + // gulp.src(__dirname + '/../templates/controller/controller.js') + // .pipe(template(answers)) + // .pipe(rename(answers.fileName + '-controller.js')) + // .pipe(conflict(options.base + options.appDir + '/components/' + answers.module)) + // .pipe(gulp.dest(options.base + options.appDir + '/components/' + answers.module)) + // .on('finish', function() { + // done(); + // }); }); }); } diff --git a/test/cases/controller.test.spec.js b/test/cases/controller.test.spec.js index bae2baf..b5c6ea1 100644 --- a/test/cases/controller.test.spec.js +++ b/test/cases/controller.test.spec.js @@ -14,7 +14,7 @@ process.chdir(__dirname); testingUtil.mockPrompt({ module: 'module1', - fileName: 'default', + fileName: 'mycontroller', spec: true }); util.setRuntimeMode('TEST'); @@ -34,8 +34,8 @@ // _.each(mockGulpDest.files(), function (item) { // console.log('mockGulpDest', item); // }); - mockGulpDest.assertDestContains('default-controller.js'); - mockGulpDest.assertDestContains('default-controller.spec.js'); + mockGulpDest.assertDestContains('mycontroller-controller.js'); + mockGulpDest.assertDestContains('mycontroller-controller.spec.js'); done(); }); }); diff --git a/test/top.js b/test/top.js index fa429fc..2ae0205 100644 --- a/test/top.js +++ b/test/top.js @@ -21,6 +21,27 @@ }, { description: 'Test controller generator with test', testcase: './cases/controller.test.spec' + }, { + description: 'Test controller generator without test', + testcase: './cases/controller.spec' + }, { + description: 'Test decorator generator', + testcase: './cases/decorator.spec' + }, { + description: 'Test directive generator', + testcase: './cases/directive.spec' + }, { + description: 'Test factory generator', + testcase: './cases/factory.spec' + }, { + description: 'Test filter generator', + testcase: './cases/filter.spec' + }, { + description: 'Test module with config generator', + testcase: './cases/module.config.spec' + }, { + description: 'Test module with route generator', + testcase: './cases/module.route.spec' }]; require('blanket')({ From 145c50f26aaef7916a33e36bc1cc84220aa46e7c Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sat, 1 Aug 2015 17:10:53 -0400 Subject: [PATCH 6/8] Logaccly completed half of the testcases 26/55 --- test/cases/controller.spec.js | 39 ++++++++++++++++++++++++++++++++ test/cases/decorator.spec.js | 36 +++++++++++++++++++++++++++++ test/cases/directive.spec.js | 36 +++++++++++++++++++++++++++++ test/cases/factory.spec.js | 36 +++++++++++++++++++++++++++++ test/cases/filter.spec.js | 36 +++++++++++++++++++++++++++++ test/cases/module.config.spec.js | 36 +++++++++++++++++++++++++++++ test/cases/module.route.spec.js | 36 +++++++++++++++++++++++++++++ 7 files changed, 255 insertions(+) create mode 100644 test/cases/controller.spec.js create mode 100644 test/cases/decorator.spec.js create mode 100644 test/cases/directive.spec.js create mode 100644 test/cases/factory.spec.js create mode 100644 test/cases/filter.spec.js create mode 100644 test/cases/module.config.spec.js create mode 100644 test/cases/module.route.spec.js diff --git a/test/cases/controller.spec.js b/test/cases/controller.spec.js new file mode 100644 index 0000000..63e4af0 --- /dev/null +++ b/test/cases/controller.spec.js @@ -0,0 +1,39 @@ +(function() { + 'use strict'; + + var common = require("../common"); + var options = common.options; + var assert = common.assert; + var testingUtil = common.testingUtil; + var util = common.util; + var _ = common._; + var mockGulpDest = common.mockGulpDest; + var gulp = common.gulp; + + function beforeEach() { + process.chdir(__dirname); + testingUtil.mockPrompt({ + module: 'module1', + fileName: 'mycontroller', + spec: false + }); + util.setRuntimeMode('TEST'); + } + + it('should put the controller file in the correct directory', function(done) { + beforeEach(); + 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) { + beforeEach(); + gulp.start('controller').once('stop', function() { + // console.log('mockGulpDest', mockGulpDest.files()); + mockGulpDest.assertDestContains('mycontroller-controller.js'); + done(); + }); + }); + +})(); diff --git a/test/cases/decorator.spec.js b/test/cases/decorator.spec.js new file mode 100644 index 0000000..9984050 --- /dev/null +++ b/test/cases/decorator.spec.js @@ -0,0 +1,36 @@ +(function() { + 'use strict'; + + var common = require("../common"); + var options = common.options; + var assert = common.assert; + var testingUtil = common.testingUtil; + var mockGulpDest = common.mockGulpDest; + var gulp = common.gulp; + var util = common.util; + + function beforeEach() { + process.chdir(__dirname); + testingUtil.mockPrompt({ + module: 'module1', + fileName: 'mydecorator' + }); + util.setRuntimeMode('TEST'); + } + + it('should put the decorator file in the correct directory', function(done) { + beforeEach(); + 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) { + beforeEach(); + gulp.start('decorator').once('stop', function() { + mockGulpDest.assertDestContains('mydecorator-decorator.js'); + done(); + }); + }); + +})(); diff --git a/test/cases/directive.spec.js b/test/cases/directive.spec.js new file mode 100644 index 0000000..aa9075e --- /dev/null +++ b/test/cases/directive.spec.js @@ -0,0 +1,36 @@ +(function() { + 'use strict'; + + var common = require("../common"); + var options = common.options; + var assert = common.assert; + var testingUtil = common.testingUtil; + var mockGulpDest = common.mockGulpDest; + var gulp = common.gulp; + var util = common.util; + + function beforeEach() { + process.chdir(__dirname); + testingUtil.mockPrompt({ + module: 'module1', + fileName: 'mydirective' + }); + util.setRuntimeMode('TEST'); + } + + it('should put the directive file in the correct directory', function(done) { + beforeEach(); + 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) { + beforeEach(); + gulp.start('directive').once('stop', function() { + mockGulpDest.assertDestContains('mydirective-directive.js'); + done(); + }); + }); + +})(); diff --git a/test/cases/factory.spec.js b/test/cases/factory.spec.js new file mode 100644 index 0000000..564d737 --- /dev/null +++ b/test/cases/factory.spec.js @@ -0,0 +1,36 @@ +(function() { + 'use strict'; + + var common = require("../common"); + var options = common.options; + var assert = common.assert; + var testingUtil = common.testingUtil; + var mockGulpDest = common.mockGulpDest; + var gulp = common.gulp; + var util = common.util; + + function beforeEach() { + process.chdir(__dirname); + testingUtil.mockPrompt({ + module: 'module1', + fileName: 'myfactory' + }); + util.setRuntimeMode('TEST'); + } + + it('should put the factory file in the correct directory', function(done) { + beforeEach(); + 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) { + beforeEach(); + gulp.start('factory').once('stop', function() { + mockGulpDest.assertDestContains('myfactory-factory.js'); + done(); + }); + }); + +})(); diff --git a/test/cases/filter.spec.js b/test/cases/filter.spec.js new file mode 100644 index 0000000..ccf4c69 --- /dev/null +++ b/test/cases/filter.spec.js @@ -0,0 +1,36 @@ +(function() { + 'use strict'; + + var common = require("../common"); + var options = common.options; + var assert = common.assert; + var testingUtil = common.testingUtil; + var mockGulpDest = common.mockGulpDest; + var gulp = common.gulp; + var util = common.util; + + function beforeEach() { + process.chdir(__dirname); + testingUtil.mockPrompt({ + module: 'module1', + fileName: 'myfilter' + }); + util.setRuntimeMode('TEST'); + } + + it('should put the filter file in the correct directory', function(done) { + beforeEach(); + 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) { + beforeEach(); + gulp.start('filter').once('stop', function() { + mockGulpDest.assertDestContains('myfilter-filter.js'); + done(); + }); + }); + +})(); diff --git a/test/cases/module.config.spec.js b/test/cases/module.config.spec.js new file mode 100644 index 0000000..0aee491 --- /dev/null +++ b/test/cases/module.config.spec.js @@ -0,0 +1,36 @@ +(function() { + 'use strict'; + + var common = require("../common"); + var options = common.options; + var assert = common.assert; + var testingUtil = common.testingUtil; + var mockGulpDest = common.mockGulpDest; + var gulp = common.gulp; + var util = common.util; + + function beforeEach() { + process.chdir(__dirname); + testingUtil.mockPrompt({ + module: 'mymodule', + config: 'config' + }); + util.setRuntimeMode('TEST'); + } + + it('should put the module file in the correct directory', function(done) { + beforeEach(); + 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) { + beforeEach(); + gulp.start('module').once('stop', function() { + mockGulpDest.assertDestContains('mymodule-config.js'); + done(); + }); + }); + +})(); diff --git a/test/cases/module.route.spec.js b/test/cases/module.route.spec.js new file mode 100644 index 0000000..0afd292 --- /dev/null +++ b/test/cases/module.route.spec.js @@ -0,0 +1,36 @@ +(function() { + 'use strict'; + + var common = require("../common"); + var options = common.options; + var assert = common.assert; + var testingUtil = common.testingUtil; + var mockGulpDest = common.mockGulpDest; + var gulp = common.gulp; + var util = common.util; + + function beforeEach() { + process.chdir(__dirname); + testingUtil.mockPrompt({ + module: 'mymodule', + config: 'routes' + }); + util.setRuntimeMode('TEST'); + } + + it('should put the module file in the correct directory', function(done) { + beforeEach(); + 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) { + beforeEach(); + gulp.start('module').once('stop', function() { + mockGulpDest.assertDestContains('mymodule-routes.js'); + done(); + }); + }); + +})(); From ade8faaa1fa3f56ab5233b959a2ff348f133e673 Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sat, 1 Aug 2015 17:40:40 -0400 Subject: [PATCH 7/8] Hopefully completed with 53 cases --- test/cases/app.spec.js | 100 ++++++++++++++++++++++++++++++++++++ test/cases/negative.spec.js | 99 +++++++++++++++++++++++++++++++++++ test/cases/provider.spec.js | 36 +++++++++++++ test/cases/service.spec.js | 36 +++++++++++++ test/cases/value.spec.js | 36 +++++++++++++ test/cases/view.spec.js | 36 +++++++++++++ test/top.js | 32 +++++++----- 7 files changed, 361 insertions(+), 14 deletions(-) create mode 100644 test/cases/negative.spec.js create mode 100644 test/cases/provider.spec.js create mode 100644 test/cases/service.spec.js create mode 100644 test/cases/value.spec.js create mode 100644 test/cases/view.spec.js diff --git a/test/cases/app.spec.js b/test/cases/app.spec.js index 017d7e0..feab3c0 100644 --- a/test/cases/app.spec.js +++ b/test/cases/app.spec.js @@ -99,4 +99,104 @@ }); }); + //Deep example + describe('Todo example', function() { + it('should not add any todo example files by default', function(done) { + testingUtil.mockPrompt({ + name: 'module' + }); + gulp.start('default').once('stop', function() { + mockGulpDest.assertDestNotContains({ + 'src/app/components/todo': [ + 'todo.js', + 'todo.html', + 'todo.css', + 'todo-route.js', + 'todo-controller.spec.js', + 'todo-controller.js' + ] + }); + done(); + }); + }); + describe('When Todo example is included', function() { + function beforeEachTODO() { + testingUtil.mockPrompt({ + name: 'module', + example: ['todo'] + }); + } + it('should add a module specific template', function(done) { + beforeEachTODO(); + gulp.start('default').once('stop', function() { + mockGulpDest.assertDestContains('src/app/components/todo/todo.html'); + done(); + }); + }); + it('should add a module definition file for the Todo module', function(done) { + beforeEachTODO(); + gulp.start('default').once('stop', function() { + mockGulpDest.assertDestContains('src/app/components/todo/todo.js'); + done(); + }); + }); + it('should add a Todo controller with a corresponding test file', function(done) { + beforeEachTODO(); + gulp.start('default').once('stop', function() { + mockGulpDest.assertDestContains([ + 'src/app/components/todo/todo-controller.js', + 'src/app/components/todo/todo-controller.spec.js' + ]); + done(); + }); + }); + }); + }); + describe('CSS files', function() { + it('should add less stylesheets by default', function(done) { + testingUtil.mockPrompt({ + name: 'module', + example: ['todo'] + }); + gulp.start('default').once('stop', function() { + mockGulpDest.assertDestContains([ + 'src/app/app.less', + 'src/app/styles/_base.less', + 'src/app/components/todo/todo.less' + ]); + done(); + }); + }); + it('should add LESS stylesheets when LESS is chosen', function(done) { + testingUtil.mockPrompt({ + name: 'module', + csstype: 'less', + example: ['todo'] + }); + gulp.start('default').once('stop', function() { + mockGulpDest.assertDestContains([ + 'src/app/app.less', + 'src/app/styles/_base.less', + 'src/app/components/todo/todo.less' + ]); + done(); + }); + }); + it('should add Sass stylesheets when Sass is chosen', function(done) { + testingUtil.mockPrompt({ + name: 'module', + csstype: 'sass', + example: ['todo'] + }); + gulp.start('default').once('stop', function() { + mockGulpDest.assertDestContains([ + 'src/app/app.scss', + 'src/app/styles/_base.scss', + 'src/app/components/todo/todo.scss' + ]); + done(); + }); + }); + }); + })(); diff --git a/test/cases/negative.spec.js b/test/cases/negative.spec.js new file mode 100644 index 0000000..234b4f8 --- /dev/null +++ b/test/cases/negative.spec.js @@ -0,0 +1,99 @@ +(function() { + 'use strict'; + + var common = require("../common"); + var options = common.options; + var assert = common.assert; + var testingUtil = common.testingUtil; + var mockGulpDest = common.mockGulpDest; + var gulp = common.gulp; + var util = common.util; + + function beforeEach() { + testingUtil.mockPrompt({ + module: 'module1', + fileName: 'strangefilename', + test: true + }); + util.setRuntimeMode('LIVE'); + } + + it('test for error constant', function(done) { + beforeEach(); + assert.that(function() { + done(); + gulp.start('constant', ['test']); + }).is.throwing(); + }); + it('test for error controller', function(done) { + beforeEach(); + assert.that(function() { + done(); + gulp.start('controller'); + }).is.throwing(); + }); + it('test for error service', function(done) { + beforeEach(); + assert.that(function() { + done(); + gulp.start('service'); + }).is.throwing(); + }); + it('test for error decorator', function(done) { + beforeEach(); + assert.that(function() { + done(); + gulp.start('decorator'); + }).is.throwing(); + }); + it('test for error directive', function(done) { + beforeEach(); + assert.that(function() { + done(); + gulp.start('directive'); + }).is.throwing(); + }); + it('test for error factory', function(done) { + beforeEach(); + assert.that(function() { + done(); + gulp.start('factory'); + }).is.throwing(); + }); + it('test for error filter', function(done) { + beforeEach(); + assert.that(function() { + done(); + gulp.start('filter'); + }).is.throwing(); + }); + it('test for error provider', function(done) { + beforeEach(); + assert.that(function() { + done(); + gulp.start('provider'); + }).is.throwing(); + }); + it('test for error route', function(done) { + beforeEach(); + assert.that(function() { + done(); + gulp.start('route'); + }).is.throwing(); + }); + it('test for error value', function(done) { + beforeEach(); + assert.that(function() { + done(); + gulp.start('value'); + }).is.throwing(); + }); + it('test for error view', function(done) { + beforeEach(); + assert.that(function() { + done(); + gulp.start('view'); + }).is.throwing(); + }); + +})(); diff --git a/test/cases/provider.spec.js b/test/cases/provider.spec.js new file mode 100644 index 0000000..eefa673 --- /dev/null +++ b/test/cases/provider.spec.js @@ -0,0 +1,36 @@ +(function() { + 'use strict'; + + var common = require("../common"); + var options = common.options; + var assert = common.assert; + var testingUtil = common.testingUtil; + var mockGulpDest = common.mockGulpDest; + var gulp = common.gulp; + var util = common.util; + + function beforeEach() { + process.chdir(__dirname); + testingUtil.mockPrompt({ + module: 'module1', + fileName: 'myprovider' + }); + util.setRuntimeMode('TEST'); + } + + it('should put the provider file in the correct directory', function(done) { + beforeEach(); + 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) { + beforeEach(); + gulp.start('provider').once('stop', function() { + mockGulpDest.assertDestContains('myprovider-provider.js'); + done(); + }); + }); + +})(); diff --git a/test/cases/service.spec.js b/test/cases/service.spec.js new file mode 100644 index 0000000..9454fb1 --- /dev/null +++ b/test/cases/service.spec.js @@ -0,0 +1,36 @@ +(function() { + 'use strict'; + + var common = require("../common"); + var options = common.options; + var assert = common.assert; + var testingUtil = common.testingUtil; + var mockGulpDest = common.mockGulpDest; + var gulp = common.gulp; + var util = common.util; + + function beforeEach() { + process.chdir(__dirname); + testingUtil.mockPrompt({ + module: 'module1', + fileName: 'myservice' + }); + util.setRuntimeMode('TEST'); + } + + it('should put the service file in the correct directory', function(done) { + beforeEach(); + 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) { + beforeEach(); + gulp.start('service').once('stop', function() { + mockGulpDest.assertDestContains('myservice-service.js'); + done(); + }); + }); + +})(); diff --git a/test/cases/value.spec.js b/test/cases/value.spec.js new file mode 100644 index 0000000..eb88032 --- /dev/null +++ b/test/cases/value.spec.js @@ -0,0 +1,36 @@ +(function() { + 'use strict'; + + var common = require("../common"); + var options = common.options; + var assert = common.assert; + var testingUtil = common.testingUtil; + var mockGulpDest = common.mockGulpDest; + var gulp = common.gulp; + var util = common.util; + + function beforeEach() { + process.chdir(__dirname); + testingUtil.mockPrompt({ + module: 'module1', + fileName: 'myvalue' + }); + util.setRuntimeMode('TEST'); + } + + it('should put the value file in the correct directory', function(done) { + beforeEach(); + 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) { + beforeEach(); + gulp.start('value').once('stop', function() { + mockGulpDest.assertDestContains('myvalue-value.js'); + done(); + }); + }); + +})(); diff --git a/test/cases/view.spec.js b/test/cases/view.spec.js new file mode 100644 index 0000000..ccf9b75 --- /dev/null +++ b/test/cases/view.spec.js @@ -0,0 +1,36 @@ +(function() { + 'use strict'; + + var common = require("../common"); + var options = common.options; + var assert = common.assert; + var testingUtil = common.testingUtil; + var mockGulpDest = common.mockGulpDest; + var gulp = common.gulp; + var util = common.util; + + function beforeEach() { + process.chdir(__dirname); + testingUtil.mockPrompt({ + module: 'module1', + fileName: 'myview' + }); + util.setRuntimeMode('TEST'); + } + + it('should put the view file in the correct directory', function(done) { + beforeEach(); + 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) { + beforeEach(); + gulp.start('view').once('stop', function() { + mockGulpDest.assertDestContains('myview-view.html'); + done(); + }); + }); + +})(); diff --git a/test/top.js b/test/top.js index 2ae0205..ad5a869 100644 --- a/test/top.js +++ b/test/top.js @@ -42,6 +42,21 @@ }, { description: 'Test module with route generator', testcase: './cases/module.route.spec' + }, { + description: 'Test provider generator', + testcase: './cases/provider.spec' + }, { + description: 'Test service generator', + testcase: './cases/service.spec' + }, { + description: 'Test value generator', + testcase: './cases/value.spec' + }, { + description: 'Test view generator', + testcase: './cases/view.spec' + }, { + description: 'Test Negative usecases for generator', + testcase: './cases/negative.spec' }]; require('blanket')({ @@ -54,21 +69,10 @@ require('../slushfile'); describe('slush-angular-gulp', function() { - // before(function() { - // process.chdir(__dirname); - // }); + before(function() { + console.log('Starting...'); + }); - function beforeEach() { - process.chdir(__dirname); - testingUtil.mockPrompt({ - name: 'module', - example: ['todo'], - module: 'module1', - fileName: 'myfilename', - test: true - }); - util.setRuntimeMode('TEST'); - } _.each(testSuite, function(tCase) { importTest(tCase.description, tCase.testcase); }); From 41161e776bae1ef09f4f04c613297ecb6a3af46a Mon Sep 17 00:00:00 2001 From: reflexdemon Date: Sat, 1 Aug 2015 17:43:33 -0400 Subject: [PATCH 8/8] Bump the version --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 3d4227f..960ecc4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "slush-angular-gulp", - "version": "0.3.4", + "version": "0.3.6", "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": { @@ -8,10 +8,10 @@ "url": "https://github.com/reflexdemon/slush-angular-gulp" }, "scripts": { - "test": "NODE_ENV=test mocha -R spec test/*.spec.js", - "posttest": "NODE_ENV=test mocha -R travis-cov test/*.spec.js", - "modular": "NODE_ENV=test mocha -R spec test/top.js", - "travis": "NODE_ENV=test mocha -R travis-cov test/top.js", + "test": "NODE_ENV=test mocha -R spec test/top.js", + "posttest": "NODE_ENV=test mocha -R travis-cov test/top.js", + "old": "NODE_ENV=test mocha -R spec test/*.spec.js", + "old-travis": "NODE_ENV=test mocha -R travis-cov test/*.spec.js", "coveralls": "NODE_ENV=test ./node_modules/.bin/mocha test/*.spec.js -R mocha-lcov-reporter | ./node_modules/coveralls/bin/coveralls.js" }, "config": {