Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(blueprints): add spec/no-spec flags to all blueprints #2382

Merged
merged 2 commits into from
Oct 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions packages/angular-cli/blueprints/class/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
const stringUtils = require('ember-cli-string-utils');
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
const dynamicPathParser = require('../../utilities/dynamic-path-parser');
const Blueprint = require('ember-cli/lib/models/blueprint');
const getFiles = Blueprint.prototype.files;

module.exports = {
description: '',

anonymousOptions: [
'<class-type>'
],


availableOptions: [
{ name: 'spec', type: Boolean, default: true }
],

normalizeEntityName: function (entityName) {
var parsedPath = dynamicPathParser(this.project, entityName);

Expand All @@ -19,15 +25,25 @@ module.exports = {
var classType = options.args [2]
this.fileName = stringUtils.dasherize(options.entity.name);
if (classType) {
this.fileName += '.' + classType;
this.fileName += '.' + classType;
}
return {
return {
dynamicPath: this.dynamicPath.dir,
flat: options.flat,
fileName: this.fileName
};
},

files: function() {
var fileList = getFiles.call(this);

if (this.options && !this.options.spec) {
fileList = fileList.filter(p => p.indexOf('__name__.spec.ts') < 0);
}

return fileList;
},

fileMapTokens: function () {
// Return custom template variables here.
return {
Expand Down
19 changes: 16 additions & 3 deletions packages/angular-cli/blueprints/directive/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
var path = require('path');
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
const path = require('path');
const dynamicPathParser = require('../../utilities/dynamic-path-parser');
const stringUtils = require('ember-cli-string-utils');
const astUtils = require('../../utilities/ast-utils');
const findParentModule = require('../../utilities/find-parent-module').default;
const NodeHost = require('@angular-cli/ast-tools').NodeHost;
const Blueprint = require('ember-cli/lib/models/blueprint');
const getFiles = Blueprint.prototype.files;

module.exports = {
description: '',

availableOptions: [
{ name: 'flat', type: Boolean, default: true },
{ name: 'prefix', type: Boolean, default: true }
{ name: 'prefix', type: Boolean, default: true },
{ name: 'spec', type: Boolean, default: true }
],

beforeInstall: function() {
Expand Down Expand Up @@ -46,6 +49,16 @@ module.exports = {
};
},

files: function() {
var fileList = getFiles.call(this);

if (this.options && !this.options.spec) {
fileList = fileList.filter(p => p.indexOf('__name__.directive.spec.ts') < 0);
}

return fileList;
},

fileMapTokens: function (options) {
// Return custom template variables here.
return {
Expand Down
19 changes: 16 additions & 3 deletions packages/angular-cli/blueprints/pipe/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
var path = require('path');
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
const path = require('path');
const dynamicPathParser = require('../../utilities/dynamic-path-parser');
const stringUtils = require('ember-cli-string-utils');
const astUtils = require('../../utilities/ast-utils');
const findParentModule = require('../../utilities/find-parent-module').default;
const NodeHost = require('@angular-cli/ast-tools').NodeHost;
const Blueprint = require('ember-cli/lib/models/blueprint');
const getFiles = Blueprint.prototype.files;

module.exports = {
description: '',

availableOptions: [
{ name: 'flat', type: Boolean, default: true }
{ name: 'flat', type: Boolean, default: true },
{ name: 'spec', type: Boolean, default: true }
],

beforeInstall: function() {
Expand All @@ -34,6 +37,16 @@ module.exports = {
};
},

files: function() {
var fileList = getFiles.call(this);

if (this.options && !this.options.spec) {
fileList = fileList.filter(p => p.indexOf('__name__.pipe.spec.ts') < 0);
}

return fileList;
},

fileMapTokens: function (options) {
// Return custom template variables here.
return {
Expand Down
19 changes: 16 additions & 3 deletions packages/angular-cli/blueprints/service/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
var path = require('path');
const path = require('path');
const chalk = require('chalk');
var dynamicPathParser = require('../../utilities/dynamic-path-parser');
const dynamicPathParser = require('../../utilities/dynamic-path-parser');
const Blueprint = require('ember-cli/lib/models/blueprint');
const getFiles = Blueprint.prototype.files;

module.exports = {
description: '',

availableOptions: [
{ name: 'flat', type: Boolean, default: true }
{ name: 'flat', type: Boolean, default: true },
{ name: 'spec', type: Boolean, default: true }
],

normalizeEntityName: function (entityName) {
Expand All @@ -23,6 +26,16 @@ module.exports = {
};
},

files: function() {
var fileList = getFiles.call(this);

if (this.options && !this.options.spec) {
fileList = fileList.filter(p => p.indexOf('__name__.service.spec.ts') < 0);
}

return fileList;
},

fileMapTokens: function (options) {
// Return custom template variables here.
return {
Expand Down
12 changes: 10 additions & 2 deletions tests/acceptance/generate-class.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,17 @@ describe('Acceptance: ng generate class', function () {
it('ng generate class my-class', function () {
return ng(['generate', 'class', 'my-class']).then(() => {
expect(existsSync(path.join(testPath, 'my-class.ts'))).to.equal(true);
expect(existsSync(path.join(testPath, 'my-class.spec.ts'))).to.equal(true);
});
});


it('ng generate class my-class --no-spec', function () {
return ng(['generate', 'class', 'my-class', '--no-spec']).then(() => {
expect(existsSync(path.join(testPath, 'my-class.ts'))).to.equal(true);
expect(existsSync(path.join(testPath, 'my-class.spec.ts'))).to.equal(false);
});
});

it('ng generate class my-class model', function () {
return ng(['generate', 'class', 'my-class', 'model']).then(() => {
expect(existsSync(path.join(testPath, 'my-class.model.ts'))).to.equal(true);
Expand All @@ -46,7 +54,7 @@ describe('Acceptance: ng generate class', function () {
expect(existsSync(path.join(testPath, 'shared', 'my-class.ts'))).to.equal(true);
});
});

it(`ng generate class shared${path.sep}my-class model`, function () {
return ng(['generate', 'class', 'shared/my-class', 'model']).then(() => {
expect(existsSync(path.join(testPath, 'shared', 'my-class.model.ts'))).to.equal(true);
Expand Down
18 changes: 17 additions & 1 deletion tests/acceptance/generate-directive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,33 @@ describe('Acceptance: ng generate directive', function () {
it('my-dir --flat false', function () {
const appRoot = path.join(root, 'tmp/foo');
const testPath = path.join(appRoot, 'src/app/my-dir/my-dir.directive.ts');
const testSpecPath = path.join(appRoot, 'src/app/my-dir/my-dir.directive.spec.ts');
const appModulePath = path.join(appRoot, 'src/app/app.module.ts');

return ng(['generate', 'directive', 'my-dir', '--flat', 'false'])
.then(() => expect(existsSync(testPath)).to.equal(true))
.then(() => {
expect(existsSync(testPath)).to.equal(true);
expect(existsSync(testSpecPath)).to.equal(true);
})
.then(() => readFile(appModulePath, 'utf-8'))
.then(content => {
expect(content).matches(/import.*\bMyDirDirective\b.*from '.\/my-dir\/my-dir.directive';/);
expect(content).matches(/declarations:\s*\[[^\]]+?,\r?\n\s+MyDirDirective\r?\n/m);
});
});

it('my-dir --flat false --no-spec', function () {
const appRoot = path.join(root, 'tmp/foo');
const testPath = path.join(appRoot, 'src/app/my-dir/my-dir.directive.ts');
const testSpecPath = path.join(appRoot, 'src/app/my-dir/my-dir.directive.spec.ts');

return ng(['generate', 'directive', 'my-dir', '--flat', 'false', '--no-spec'])
.then(() => {
expect(existsSync(testPath)).to.equal(true);
expect(existsSync(testSpecPath)).to.equal(false);
});
});

it('test' + path.sep + 'my-dir', function () {
fs.mkdirsSync(path.join(root, 'tmp', 'foo', 'src', 'app', 'test'));
return ng(['generate', 'directive', 'test' + path.sep + 'my-dir', '--flat', 'false']).then(() => {
Expand Down
18 changes: 17 additions & 1 deletion tests/acceptance/generate-pipe.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,32 @@ describe('Acceptance: ng generate pipe', function () {
it('ng generate pipe my-pipe', function () {
const appRoot = path.join(root, 'tmp/foo');
const testPath = path.join(appRoot, 'src/app/my-pipe.pipe.ts');
const testSpecPath = path.join(appRoot, 'src/app/my-pipe.pipe.spec.ts');
const appModulePath = path.join(appRoot, 'src/app/app.module.ts');
return ng(['generate', 'pipe', 'my-pipe'])
.then(() => expect(existsSync(testPath)).to.equal(true))
.then(() => {
expect(existsSync(testPath)).to.equal(true);
expect(existsSync(testSpecPath)).to.equal(true);
})
.then(() => readFile(appModulePath, 'utf-8'))
.then(content => {
expect(content).matches(/import.*\bMyPipePipe\b.*from '.\/my-pipe.pipe';/);
expect(content).matches(/declarations:\s*\[[^\]]+?,\r?\n\s+MyPipePipe\r?\n/m);
});
});

it('ng generate pipe my-pipe --no-spec', function () {
const appRoot = path.join(root, 'tmp/foo');
const testPath = path.join(appRoot, 'src/app/my-pipe.pipe.ts');
const testSpecPath = path.join(appRoot, 'src/app/my-pipe.pipe.spec.ts');

return ng(['generate', 'pipe', 'my-pipe', '--no-spec'])
.then(() => {
expect(existsSync(testPath)).to.equal(true);
expect(existsSync(testSpecPath)).to.equal(false);
});
});

it('ng generate pipe test' + path.sep + 'my-pipe', function () {
fs.mkdirsSync(path.join(root, 'tmp', 'foo', 'src', 'app', 'test'));
return ng(['generate', 'pipe', 'test' + path.sep + 'my-pipe']).then(() => {
Expand Down
24 changes: 23 additions & 1 deletion tests/acceptance/generate-service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,32 @@ describe('Acceptance: ng generate service', function () {
it('ng generate service my-svc', function () {
const appRoot = path.join(root, 'tmp/foo');
const testPath = path.join(appRoot, 'src/app/my-svc.service.ts');
const testSpecPath = path.join(appRoot, 'src/app/my-svc.service.spec.ts');
const appModulePath = path.join(appRoot, 'src/app/app.module.ts');

return ng(['generate', 'service', 'my-svc'])
.then(() => expect(existsSync(testPath)).to.equal(true))
.then(() => {
expect(existsSync(testPath)).to.equal(true);
expect(existsSync(testSpecPath)).to.equal(true);
})
.then(() => readFile(appModulePath, 'utf-8'))
.then(content => {
expect(content).not.to.matches(/import.*\MySvcService\b.*from '.\/my-svc.service';/);
expect(content).not.to.matches(/providers:\s*\[MySvcService\]/m);
});
});

it('ng generate service my-svc --no-spec', function () {
const appRoot = path.join(root, 'tmp/foo');
const testPath = path.join(appRoot, 'src/app/my-svc.service.ts');
const testSpecPath = path.join(appRoot, 'src/app/my-svc.service.spec.ts');
const appModulePath = path.join(appRoot, 'src/app/app.module.ts');

return ng(['generate', 'service', 'my-svc', '--no-spec'])
.then(() => {
expect(existsSync(testPath)).to.equal(true);
expect(existsSync(testSpecPath)).to.equal(false);
})
.then(() => readFile(appModulePath, 'utf-8'))
.then(content => {
expect(content).not.to.matches(/import.*\MySvcService\b.*from '.\/my-svc.service';/);
Expand Down