Skip to content

Commit

Permalink
feat(module): component optional when generating module (#3389)
Browse files Browse the repository at this point in the history
* change URL query key name

* generate component with module made optional

* revert changes done to module cause open PR

* components when generating module is optional

* tests updated for component flag

* fix parent/child compnent test to fit new flag

* updated test for parent/child module generate

* removed component testing from basic module e2e

* adjusted e2e test for generate module

* ng g m creates module only with routing flag

* unit test for new generate module behavior

* e2e tests for g m new behavior

* remove spec test

* shorten test module name to keep 100 char limit
  • Loading branch information
baruchvlz authored and hansl committed Dec 9, 2016
1 parent 0b5dc74 commit 2fb2d13
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 28 deletions.
22 changes: 12 additions & 10 deletions packages/angular-cli/blueprints/module/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
};
21 changes: 21 additions & 0 deletions tests/acceptance/generate-module.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
})
);
Expand Down
16 changes: 7 additions & 9 deletions tests/e2e/tests/generate/module/module-basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
19 changes: 10 additions & 9 deletions tests/e2e/tests/generate/module/module-routing.ts
Original file line number Diff line number Diff line change
@@ -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'));
}

0 comments on commit 2fb2d13

Please sign in to comment.