Skip to content

Commit

Permalink
add tests directory option
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinspecker committed Jul 25, 2014
1 parent 30f2f94 commit a93f8d8
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 28 deletions.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
```
Expand Down Expand Up @@ -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
Expand All @@ -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');
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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();
Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions app/templates/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion app/templates/karma.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
Expand Down
2 changes: 1 addition & 1 deletion constant/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
2 changes: 1 addition & 1 deletion controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
2 changes: 1 addition & 1 deletion directive/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
2 changes: 1 addition & 1 deletion factory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
2 changes: 1 addition & 1 deletion filter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
3 changes: 2 additions & 1 deletion genBase/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
};
};

Expand Down
2 changes: 1 addition & 1 deletion provider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
2 changes: 1 addition & 1 deletion service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
25 changes: 14 additions & 11 deletions test/test-creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('ng-poly generator', function () {
'markup': 'html',
'appScript': 'js',
'testScript': 'js',
'testDir': 'src',
'style': 'less'
});

Expand Down Expand Up @@ -72,13 +73,15 @@ describe('ng-poly generator', function () {
'markup': 'html',
'appScript': 'js',
'testScript': 'js',
'testDir': 'src',
'style': 'less'
},
{
'appName': 'temp',
'markup': 'jade',
'appScript': 'js',
'testScript': 'coffee',
'testDir': 'test',
'style': 'less'
}];

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -172,22 +175,22 @@ 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'
});

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'
});
Expand All @@ -200,51 +203,51 @@ 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'
});

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'
});

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'
});

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'
});
Expand Down
1 change: 1 addition & 0 deletions test/test-file-manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe('file manipulation', function () {
'markup': 'html',
'appScript': 'js',
'testScript': 'js',
'testDir': 'src',
'style': 'less'
});

Expand Down
2 changes: 1 addition & 1 deletion value/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

0 comments on commit a93f8d8

Please sign in to comment.