diff --git a/package.json b/package.json index f43d2d7..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,8 +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", + "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": { diff --git a/tasks/controller.js b/tasks/controller.js index 0d452f9..8e4bd95 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 ".'); - } - - 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') - .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)) + 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 ".'); } - //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(); - }); + + 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(); + }); + + } 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.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/app.spec.js b/test/cases/app.spec.js new file mode 100644 index 0000000..feab3c0 --- /dev/null +++ b/test/cases/app.spec.js @@ -0,0 +1,202 @@ +(function() { + 'use strict'; + + var common = require("../common"); + 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()).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', + '.csslintrc', + '.editorconfig', + '.gitignore', + '.jshintrc' + ]); + done(); + }); + }); + it('should add bower.json and package.json to project root', function(done) { + beforeEach(); + gulp.start('default').once('stop', function() { + mockGulpDest.assertDestContains([ + 'package.json', + 'bower.json' + ]); + done(); + }); + }); + 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(); + }); + }); + it('should add a JavaScript app module definition file by default', function(done) { + 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(); + }); + }); + + //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/constant.spec.js b/test/cases/constant.spec.js new file mode 100644 index 0000000..1a9b4ba --- /dev/null +++ b/test/cases/constant.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 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() { + mockGulpDest.assertDestContains('myconstant-constant.js') + done(); + }); + }); + +})(); 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/controller.test.spec.js b/test/cases/controller.test.spec.js new file mode 100644 index 0000000..b5c6ea1 --- /dev/null +++ b/test/cases/controller.test.spec.js @@ -0,0 +1,43 @@ +(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: 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() { + var files = []; + // _.each(mockGulpDest.files(), function (item) { + // console.log('mockGulpDest', item); + // }); + mockGulpDest.assertDestContains('mycontroller-controller.js'); + mockGulpDest.assertDestContains('mycontroller-controller.spec.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(); + }); + }); + +})(); 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/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/top.js b/test/top.js new file mode 100644 index 0000000..ad5a869 --- /dev/null +++ b/test/top.js @@ -0,0 +1,86 @@ +(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: './cases/app.spec' + }, { + description: 'Test the Constants generator', + testcase: './cases/constant.spec' + }, { + 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' + }, { + 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')({ + pattern: function(filename) { + return !/node_modules/.test(filename); + } + }); + + //Load the main slush file for testing + require('../slushfile'); + + describe('slush-angular-gulp', function() { + before(function() { + console.log('Starting...'); + }); + + _.each(testSuite, function(tCase) { + importTest(tCase.description, tCase.testcase); + }); + + + after(function() { + console.log('Completed.'); + }); + }); + +})();