diff --git a/packages/angular-cli/blueprints/module/index.js b/packages/angular-cli/blueprints/module/index.js index 1ee4be43aea8..c82dfdfa282a 100644 --- a/packages/angular-cli/blueprints/module/index.js +++ b/packages/angular-cli/blueprints/module/index.js @@ -59,16 +59,18 @@ module.exports = { afterInstall: function (options) { // Note that `this.generatePath` already contains `this.dasherizedModuleName` - // So, the path will end like `name/name`, + // So, the path will end like `name/name`, // which is correct for `name.component.ts` created in module `name` - var componentPath = path.join(this.generatePath, this.dasherizedModuleName); - options.entity.name = path.relative(this.dynamicPath.appRoot, componentPath); - options.flat = true; - options.route = false; - options.inlineTemplate = false; - options.inlineStyle = false; - options.prefix = true; - options.spec = true; - return Blueprint.load(path.join(__dirname, '../component')).install(options); + if (this.options && this.options.routing) { + var componentPath = path.join(this.generatePath, this.dasherizedModuleName); + options.entity.name = path.relative(this.dynamicPath.appRoot, componentPath); + options.flat = true; + options.route = false; + options.inlineTemplate = false; + options.inlineStyle = false; + options.prefix = true; + options.spec = true; + return Blueprint.load(path.join(__dirname, '../component')).install(options); + } } }; diff --git a/tests/acceptance/generate-module.spec.js b/tests/acceptance/generate-module.spec.js index fef9a2ed5091..a4e38274da4c 100644 --- a/tests/acceptance/generate-module.spec.js +++ b/tests/acceptance/generate-module.spec.js @@ -35,9 +35,19 @@ describe('Acceptance: ng generate module', function () { return ng(['generate', 'module', 'my-module']).then(() => { expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true); expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.spec.ts'))).to.equal(false); + expect(existsSync(path.join(testPath, 'my-module', 'my-module.component.ts'))).to.equal(false); }); }); + it('ng generate module generate routing and component files when passed flag --routing', function () { + return ng(['generate', 'module', 'my-module', '--routing']).then( () => { + expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true); + expect(existsSync(path.join(testPath, 'my-module', 'my-module-routing.module.ts'))).to.equal(true); + expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.spec.ts'))).to.equal(false); + expect(existsSync(path.join(testPath, 'my-module', 'my-module.component.ts'))).to.equal(true); + }) + }); + it('ng generate module my-module --spec', function () { return ng(['generate', 'module', 'my-module', '--spec']).then(() => { expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true); @@ -57,6 +67,17 @@ describe('Acceptance: ng generate module', function () { ng(['generate', 'module', 'parent/child']).then(() => { expect(existsSync(path.join(testPath, 'parent/child', 'child.module.ts'))).to.equal(true); expect(existsSync(path.join(testPath, 'parent/child', 'child.module.spec.ts'))).to.equal(false); + expect(existsSync(path.join(testPath, 'parent/child', 'child.component.ts'))).to.equal(false); + }) + ); + }); + + it('ng generate module should generate parent/child module with routing and component files when passed --routing flag', function () { + return ng(['generate', 'module', 'parent']).then(() => + ng(['generate', 'module', 'parent/child', '--routing']).then(() => { + expect(existsSync(path.join(testPath, 'parent/child', 'child.module.ts'))).to.equal(true); + expect(existsSync(path.join(testPath, 'parent/child', 'child-routing.module.ts'))).to.equal(true); + expect(existsSync(path.join(testPath, 'parent/child', 'child.module.spec.ts'))).to.equal(false); expect(existsSync(path.join(testPath, 'parent/child', 'child.component.ts'))).to.equal(true); }) ); diff --git a/tests/e2e/tests/generate/module/module-basic.ts b/tests/e2e/tests/generate/module/module-basic.ts index 071c20f3bea7..382aad79f871 100644 --- a/tests/e2e/tests/generate/module/module-basic.ts +++ b/tests/e2e/tests/generate/module/module-basic.ts @@ -5,17 +5,15 @@ import {expectToFail} from '../../../utils/utils'; export default function() { - const moduleDir = join('src', 'app', 'test-module'); + const moduleDir = join('src', 'app', 'test'); - return ng('generate', 'module', 'test-module') + return ng('generate', 'module', 'test') .then(() => expectFileToExist(moduleDir)) - .then(() => expectFileToExist(join(moduleDir, 'test-module.module.ts'))) - .then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test-module.routing.ts')))) - .then(() => expectFileToExist(join(moduleDir, 'test-module.component.ts'))) - .then(() => expectFileToExist(join(moduleDir, 'test-module.component.spec.ts'))) - .then(() => expectFileToExist(join(moduleDir, 'test-module.component.html'))) - .then(() => expectFileToExist(join(moduleDir, 'test-module.component.css'))) - .then(() => expectFileToMatch(join(moduleDir, 'test-module.module.ts'), 'TestModuleComponent')) + .then(() => expectFileToExist(join(moduleDir, 'test.module.ts'))) + .then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test-routing.module.ts')))) + .then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test.component.ts')))) + .then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test.spec.ts')))) + .then(() => expectFileToMatch(join(moduleDir, 'test.module.ts'), 'TestModule')) // Try to run the unit tests. .then(() => ng('test', '--single-run')); diff --git a/tests/e2e/tests/generate/module/module-routing.ts b/tests/e2e/tests/generate/module/module-routing.ts index 851d7ebdcf41..8b98e39d5918 100644 --- a/tests/e2e/tests/generate/module/module-routing.ts +++ b/tests/e2e/tests/generate/module/module-routing.ts @@ -1,20 +1,21 @@ import {join} from 'path'; import {ng} from '../../../utils/process'; import {expectFileToExist} from '../../../utils/fs'; +import {expectToFail} from '../../../utils/utils'; export default function() { - const moduleDir = join('src', 'app', 'test-module'); + const moduleDir = join('src', 'app', 'test'); - return ng('generate', 'module', 'test-module', '--routing') + return ng('generate', 'module', 'test', '--routing') .then(() => expectFileToExist(moduleDir)) - .then(() => expectFileToExist(join(moduleDir, 'test-module.module.ts'))) - .then(() => expectFileToExist(join(moduleDir, 'test-module-routing.module.ts'))) - .then(() => expectFileToExist(join(moduleDir, 'test-module.component.ts'))) - .then(() => expectFileToExist(join(moduleDir, 'test-module.component.spec.ts'))) - .then(() => expectFileToExist(join(moduleDir, 'test-module.component.html'))) - .then(() => expectFileToExist(join(moduleDir, 'test-module.component.css'))) - + .then(() => expectFileToExist(join(moduleDir, 'test.module.ts'))) + .then(() => expectFileToExist(join(moduleDir, 'test-routing.module.ts'))) + .then(() => expectFileToExist(join(moduleDir, 'test.component.ts'))) + .then(() => expectFileToExist(join(moduleDir, 'test.component.spec.ts'))) + .then(() => expectFileToExist(join(moduleDir, 'test.component.html'))) + .then(() => expectFileToExist(join(moduleDir, 'test.component.css'))) + .then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test.spec.ts')))) // Try to run the unit tests. .then(() => ng('test', '--single-run')); }