From a93f8d83fbd247b8fa254ce5179e034d36666463 Mon Sep 17 00:00:00 2001 From: Dustin Specker Date: Fri, 25 Jul 2014 11:04:39 -0500 Subject: [PATCH] add tests directory option --- README.md | 21 ++++++++++++++++----- app/index.js | 17 +++++++++++++++++ app/templates/gulpfile.js | 4 ++-- app/templates/karma.config.json | 2 +- constant/index.js | 2 +- controller/index.js | 2 +- directive/index.js | 2 +- factory/index.js | 2 +- filter/index.js | 2 +- genBase/index.js | 3 ++- provider/index.js | 2 +- service/index.js | 2 +- test/test-creation.js | 25 ++++++++++++++----------- test/test-file-manipulation.js | 1 + value/index.js | 2 +- 15 files changed, 61 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index cb64227..aa08007 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ yo ng-poly:view --module=home/kitchen * * * ### App -Asks for application name and language preferences to scaffold out an application with a home module. Then installs npm and Bower dependencies. +Asks for application name and language preferences to scaffold out an application with a home module. It will also ask if tests should be placed in the `src/` or `tests/` directory. Then installs npm and Bower dependencies. Example: ``` @@ -318,7 +318,9 @@ Produces `src/top/top.js`: ```javascript 'use strict'; -angular.module('top', ['ui.router']); +angular.module('top', [ + 'ui.router' +]); angular.module('top').config(function ($stateProvider) { $stateProvider @@ -336,7 +338,11 @@ Updates `src/app.js`: ```javascript 'use strict'; -angular.module('module', ['ui.router', 'home', 'top']); +angular.module('module', [ + 'ui.router', + 'home', + 'top' +]); angular.module('module').config(function ($urlRouterProvider) { $urlRouterProvider.otherwise('/home'); @@ -356,7 +362,10 @@ Updates `src/top/top.js`: ```javascript 'use strict'; -angular.module('top', ['ui.router', 'top.bottom']); +angular.module('top', [ + 'ui.router', + 'top.bottom' +]); angular.module('top').config(function ($stateProvider) { $stateProvider @@ -439,7 +448,9 @@ Updates `src/module/module.js`: ```javascript 'use strict'; -angular.module('module', ['ui.router']); +angular.module('module', [ + 'ui.router' +]); angular.module('module').config(function ($stateProvider) { $stateProvider diff --git a/app/index.js b/app/index.js index 5001046..f6b6d33 100644 --- a/app/index.js +++ b/app/index.js @@ -61,6 +61,21 @@ Generator.prototype.prompting = function prompting() { } ] }, + { + type: 'list', + name: 'testDir', + message: 'Where should tests be saved?', + choices: [ + { + name: 'src/', + value: 'src' + }, + { + name: 'test/', + value: 'test' + } + ] + }, { type: 'list', name: 'style', @@ -77,6 +92,7 @@ Generator.prototype.prompting = function prompting() { this.markup = props.markup; this.appScript = props.appScript; this.testScript = props.testScript; + this.testDir = props.testDir; this.style = props.style; done(); @@ -94,6 +110,7 @@ Generator.prototype.configuring = function configuring() { this.config.set('markup', this.markup); this.config.set('appScript', this.appScript); this.config.set('testScript', this.testScript); + this.config.set('testDir', this.testDir); this.config.set('style', this.style); this.config.save(); diff --git a/app/templates/gulpfile.js b/app/templates/gulpfile.js index 3051510..a130e43 100644 --- a/app/templates/gulpfile.js +++ b/app/templates/gulpfile.js @@ -46,7 +46,7 @@ var componentsBase = 'src/components/' , srcLessFiles = 'src/**/*.less'; // since we need to strictly specify style.less later // test files -var unitTests = 'src/**/*_test.{coffee,js}'; +var unitTests = '{src,test}/**/*_test.{coffee,js}'; // build files var build = 'build/' @@ -143,7 +143,7 @@ gulp.task('karmaInject', function () { 'bower_components/angular-ui-router/release/angular-ui-router.js', ]).pipe(angularSort())); stream.queue(gulp.src([ - 'src/**/*_test.*' + unitTests ])); return gulp.src('./karma.config.json') .pipe(inject(stream.done(), diff --git a/app/templates/karma.config.json b/app/templates/karma.config.json index 610ce88..c24b2d4 100644 --- a/app/templates/karma.config.json +++ b/app/templates/karma.config.json @@ -8,7 +8,7 @@ "src/**/!(*_test)+(.js)": ["coverage"], "src/**/*-directive.tpl.html": ["ng-html2js"], "src/**/*-directive.tpl.jade": ["ng-jade2js"], - "src/**/*_test.coffee": ["coffee"] + "**/*_test.coffee": ["coffee"] }, "ngHtml2JsPreprocessor": { "stripPrefix": "src/" diff --git a/constant/index.js b/constant/index.js index 865c4dc..f8f48e5 100644 --- a/constant/index.js +++ b/constant/index.js @@ -22,5 +22,5 @@ Generator.prototype.writing = function writing() { this.template('_constant.js', path.join('src', config.modulePath, config.hyphenName+ '-constant.js'), config); this.template('_spec.' + config.testScript, - path.join('src', config.modulePath, config.hyphenName + '-constant_test.' + config.testScript), config); + path.join(config.testDir, config.modulePath, config.hyphenName + '-constant_test.' + config.testScript), config); }; \ No newline at end of file diff --git a/controller/index.js b/controller/index.js index 0d78bb7..5aa8eb0 100644 --- a/controller/index.js +++ b/controller/index.js @@ -23,5 +23,5 @@ Generator.prototype.writing = function writing() { this.template('_controller.js', path.join('src', config.modulePath, config.hyphenName + '-controller.js'), config); this.template('_spec.' + config.testScript, - path.join('src', config.modulePath, config.hyphenName + '-controller_test.' + config.testScript), config); + path.join(config.testDir, config.modulePath, config.hyphenName + '-controller_test.' + config.testScript), config); }; \ No newline at end of file diff --git a/directive/index.js b/directive/index.js index a6eef70..738b9e9 100644 --- a/directive/index.js +++ b/directive/index.js @@ -24,5 +24,5 @@ Generator.prototype.writing = function writing() { this.template('_directive.' + config.markup, path.join('src', config.modulePath, config.hyphenName + '-directive.tpl.' + config.markup), config); this.template('_spec.' + config.testScript, - path.join('src', config.modulePath, config.hyphenName + '-directive_test.' + config.testScript), config); + path.join(config.testDir, config.modulePath, config.hyphenName + '-directive_test.' + config.testScript), config); }; \ No newline at end of file diff --git a/factory/index.js b/factory/index.js index 870260e..95a27c4 100644 --- a/factory/index.js +++ b/factory/index.js @@ -22,5 +22,5 @@ Generator.prototype.writing = function writing() { this.template('_factory.js', path.join('src', config.modulePath, config.hyphenName + '-factory.js'), config); this.template('_spec.' + config.testScript, - path.join('src', config.modulePath, config.hyphenName + '-factory_test.' + config.testScript), config); + path.join(config.testDir, config.modulePath, config.hyphenName + '-factory_test.' + config.testScript), config); }; \ No newline at end of file diff --git a/filter/index.js b/filter/index.js index db38353..cb1ec92 100644 --- a/filter/index.js +++ b/filter/index.js @@ -22,5 +22,5 @@ Generator.prototype.writing = function writing() { this.template('_filter.js', path.join('src', config.modulePath, config.hyphenName + '-filter.js'), config); this.template('_spec.' + config.testScript, - path.join('src', config.modulePath, config.hyphenName + '-filter_test.' + config.testScript), config); + path.join(config.testDir, config.modulePath, config.hyphenName + '-filter_test.' + config.testScript), config); }; \ No newline at end of file diff --git a/genBase/index.js b/genBase/index.js index ad1ca5a..25596fd 100644 --- a/genBase/index.js +++ b/genBase/index.js @@ -42,7 +42,8 @@ Generator.prototype.getConfig = function getConfig() { upperCamel: utils.upperCamel(this.name), modulePath: this.module, markup: this.config.get('markup'), - testScript: this.config.get('testScript') + testScript: this.config.get('testScript'), + testDir: this.config.get('testDir') }; }; diff --git a/provider/index.js b/provider/index.js index ab9855a..e9de3e6 100644 --- a/provider/index.js +++ b/provider/index.js @@ -22,5 +22,5 @@ Generator.prototype.writing = function writing() { this.template('_provider.js', path.join('src', config.modulePath, config.hyphenName + '-provider.js'), config); this.template('_spec.' + config.testScript, - path.join('src', config.modulePath, config.hyphenName + '-provider_test.' + config.testScript), config); + path.join(config.testDir, config.modulePath, config.hyphenName + '-provider_test.' + config.testScript), config); }; \ No newline at end of file diff --git a/service/index.js b/service/index.js index 0deaf2a..31a9cf9 100644 --- a/service/index.js +++ b/service/index.js @@ -22,5 +22,5 @@ Generator.prototype.writing = function writing() { this.template('_service.js', path.join('src', config.modulePath, config.hyphenName + '-service.js'), config); this.template('_spec.' + config.testScript, - path.join('src', config.modulePath, config.hyphenName + '-service_test.' + config.testScript), config); + path.join(config.testDir, config.modulePath, config.hyphenName + '-service_test.' + config.testScript), config); }; \ No newline at end of file diff --git a/test/test-creation.js b/test/test-creation.js index a91efec..450bcd2 100644 --- a/test/test-creation.js +++ b/test/test-creation.js @@ -44,6 +44,7 @@ describe('ng-poly generator', function () { 'markup': 'html', 'appScript': 'js', 'testScript': 'js', + 'testDir': 'src', 'style': 'less' }); @@ -72,6 +73,7 @@ describe('ng-poly generator', function () { 'markup': 'html', 'appScript': 'js', 'testScript': 'js', + 'testDir': 'src', 'style': 'less' }, { @@ -79,6 +81,7 @@ describe('ng-poly generator', function () { 'markup': 'jade', 'appScript': 'js', 'testScript': 'coffee', + 'testDir': 'test', 'style': 'less' }]; @@ -131,7 +134,7 @@ describe('ng-poly generator', function () { 'src/home/home.tpl.' + config.markup, 'src/home/home.' + config.style, 'src/home/home-controller.' + config.appScript, - 'src/home/home-controller_test.' + config.testScript, + config.testDir + '/home/home-controller_test.' + config.testScript, 'src/app.' + config.appScript, 'src/index.' + config.markup, '.editorconfig', @@ -172,14 +175,14 @@ describe('ng-poly generator', function () { testGenerator('constant', ['../../constant'], expected.concat( 'src/home/constant-test-constant.' + config.appScript, - 'src/home/constant-test-constant_test.' + config.testScript + config.testDir + '/home/constant-test-constant_test.' + config.testScript ), { module: 'home' }); testGenerator('controller', ['../../controller'], expected.concat( 'src/home/controller-test-controller.' + config.appScript, - 'src/home/controller-test-controller_test.' + config.testScript + config.testDir + '/home/controller-test-controller_test.' + config.testScript ), { module: 'home' }); @@ -187,7 +190,7 @@ describe('ng-poly generator', function () { testGenerator('directive', ['../../directive'], expected.concat( 'src/home/directive-test-directive.tpl.' + config.markup, 'src/home/directive-test-directive.' + config.appScript, - 'src/home/directive-test-directive_test.' + config.testScript + config.testDir + '/home/directive-test-directive_test.' + config.testScript ), { module: 'home' }); @@ -200,14 +203,14 @@ describe('ng-poly generator', function () { testGenerator('factory', ['../../factory'], expected.concat( 'src/home/factory-test-factory.' + config.appScript, - 'src/home/factory-test-factory_test.' + config.testScript + config.testDir + '/home/factory-test-factory_test.' + config.testScript ), { module: 'home' }); testGenerator('filter', ['../../filter'], expected.concat( 'src/home/filter-test-filter.' + config.appScript, - 'src/home/filter-test-filter_test.' + config.testScript + config.testDir + '/home/filter-test-filter_test.' + config.testScript ), { module: 'home' }); @@ -215,13 +218,13 @@ describe('ng-poly generator', function () { testGenerator('module', ['../../module', '../../controller', '../../view'], expected.concat( 'src/module-test/module-test.' + config.appScript, 'src/module-test/module-test-controller.' + config.appScript, - 'src/module-test/module-test-controller_test.' + config.testScript, + config.testDir + '/module-test/module-test-controller_test.' + config.testScript, 'src/module-test/module-test.tpl.' + config.markup )); testGenerator('provider', ['../../provider'], expected.concat( 'src/home/provider-test-provider.' + config.appScript, - 'src/home/provider-test-provider_test.' + config.testScript + config.testDir + '/home/provider-test-provider_test.' + config.testScript ), { module: 'home' }); @@ -229,7 +232,7 @@ describe('ng-poly generator', function () { testGenerator('route', ['../../route', '../../controller', '../../view'], ( 'src/home/route-test.tpl.' + config.markup, 'src/home/route-test-controller.' + config.appScript, - 'src/home/route-test-controller_test.' + config.testScript + config.testDir + '/home/route-test-controller_test.' + config.testScript ), { 'module': 'home', 'url': 'value' @@ -237,14 +240,14 @@ describe('ng-poly generator', function () { testGenerator('service', ['../../service'], expected.concat( 'src/home/service-test-service.' + config.appScript, - 'src/home/service-test-service_test.' + config.testScript + config.testDir + '/home/service-test-service_test.' + config.testScript ), { module: 'home' }); testGenerator('value', ['../../value'], expected.concat( 'src/home/value-test-value.' + config.appScript, - 'src/home/value-test-value_test.' + config.testScript + config.testDir + '/home/value-test-value_test.' + config.testScript ), { module: 'home' }); diff --git a/test/test-file-manipulation.js b/test/test-file-manipulation.js index 91c7ae3..4d6543b 100644 --- a/test/test-file-manipulation.js +++ b/test/test-file-manipulation.js @@ -25,6 +25,7 @@ describe('file manipulation', function () { 'markup': 'html', 'appScript': 'js', 'testScript': 'js', + 'testDir': 'src', 'style': 'less' }); diff --git a/value/index.js b/value/index.js index df688bb..5f1ad64 100644 --- a/value/index.js +++ b/value/index.js @@ -22,5 +22,5 @@ Generator.prototype.writing = function writing() { this.template('_value.js', path.join('src', config.modulePath, config.hyphenName + '-value.js'), config); this.template('_spec.' + config.testScript, - path.join('src', config.modulePath, config.hyphenName + '-value_test.' + config.testScript), config); + path.join(config.testDir, config.modulePath, config.hyphenName + '-value_test.' + config.testScript), config); }; \ No newline at end of file