Skip to content

Commit ead6349

Browse files
baruchvlzMRHarrison
authored andcommitted
feat(module): component optional when generating module (angular#3389)
* 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
1 parent b5d0ccc commit ead6349

File tree

4 files changed

+50
-28
lines changed

4 files changed

+50
-28
lines changed

packages/angular-cli/blueprints/module/index.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,18 @@ module.exports = {
5959

6060
afterInstall: function (options) {
6161
// Note that `this.generatePath` already contains `this.dasherizedModuleName`
62-
// So, the path will end like `name/name`,
62+
// So, the path will end like `name/name`,
6363
// which is correct for `name.component.ts` created in module `name`
64-
var componentPath = path.join(this.generatePath, this.dasherizedModuleName);
65-
options.entity.name = path.relative(this.dynamicPath.appRoot, componentPath);
66-
options.flat = true;
67-
options.route = false;
68-
options.inlineTemplate = false;
69-
options.inlineStyle = false;
70-
options.prefix = true;
71-
options.spec = true;
72-
return Blueprint.load(path.join(__dirname, '../component')).install(options);
64+
if (this.options && this.options.routing) {
65+
var componentPath = path.join(this.generatePath, this.dasherizedModuleName);
66+
options.entity.name = path.relative(this.dynamicPath.appRoot, componentPath);
67+
options.flat = true;
68+
options.route = false;
69+
options.inlineTemplate = false;
70+
options.inlineStyle = false;
71+
options.prefix = true;
72+
options.spec = true;
73+
return Blueprint.load(path.join(__dirname, '../component')).install(options);
74+
}
7375
}
7476
};

tests/acceptance/generate-module.spec.js

+21
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,19 @@ describe('Acceptance: ng generate module', function () {
3535
return ng(['generate', 'module', 'my-module']).then(() => {
3636
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true);
3737
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.spec.ts'))).to.equal(false);
38+
expect(existsSync(path.join(testPath, 'my-module', 'my-module.component.ts'))).to.equal(false);
3839
});
3940
});
4041

42+
it('ng generate module generate routing and component files when passed flag --routing', function () {
43+
return ng(['generate', 'module', 'my-module', '--routing']).then( () => {
44+
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true);
45+
expect(existsSync(path.join(testPath, 'my-module', 'my-module-routing.module.ts'))).to.equal(true);
46+
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.spec.ts'))).to.equal(false);
47+
expect(existsSync(path.join(testPath, 'my-module', 'my-module.component.ts'))).to.equal(true);
48+
})
49+
});
50+
4151
it('ng generate module my-module --spec', function () {
4252
return ng(['generate', 'module', 'my-module', '--spec']).then(() => {
4353
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.ts'))).to.equal(true);
@@ -57,6 +67,17 @@ describe('Acceptance: ng generate module', function () {
5767
ng(['generate', 'module', 'parent/child']).then(() => {
5868
expect(existsSync(path.join(testPath, 'parent/child', 'child.module.ts'))).to.equal(true);
5969
expect(existsSync(path.join(testPath, 'parent/child', 'child.module.spec.ts'))).to.equal(false);
70+
expect(existsSync(path.join(testPath, 'parent/child', 'child.component.ts'))).to.equal(false);
71+
})
72+
);
73+
});
74+
75+
it('ng generate module should generate parent/child module with routing and component files when passed --routing flag', function () {
76+
return ng(['generate', 'module', 'parent']).then(() =>
77+
ng(['generate', 'module', 'parent/child', '--routing']).then(() => {
78+
expect(existsSync(path.join(testPath, 'parent/child', 'child.module.ts'))).to.equal(true);
79+
expect(existsSync(path.join(testPath, 'parent/child', 'child-routing.module.ts'))).to.equal(true);
80+
expect(existsSync(path.join(testPath, 'parent/child', 'child.module.spec.ts'))).to.equal(false);
6081
expect(existsSync(path.join(testPath, 'parent/child', 'child.component.ts'))).to.equal(true);
6182
})
6283
);

tests/e2e/tests/generate/module/module-basic.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ import {expectToFail} from '../../../utils/utils';
55

66

77
export default function() {
8-
const moduleDir = join('src', 'app', 'test-module');
8+
const moduleDir = join('src', 'app', 'test');
99

10-
return ng('generate', 'module', 'test-module')
10+
return ng('generate', 'module', 'test')
1111
.then(() => expectFileToExist(moduleDir))
12-
.then(() => expectFileToExist(join(moduleDir, 'test-module.module.ts')))
13-
.then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test-module.routing.ts'))))
14-
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.ts')))
15-
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.spec.ts')))
16-
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.html')))
17-
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.css')))
18-
.then(() => expectFileToMatch(join(moduleDir, 'test-module.module.ts'), 'TestModuleComponent'))
12+
.then(() => expectFileToExist(join(moduleDir, 'test.module.ts')))
13+
.then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test-routing.module.ts'))))
14+
.then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test.component.ts'))))
15+
.then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test.spec.ts'))))
16+
.then(() => expectFileToMatch(join(moduleDir, 'test.module.ts'), 'TestModule'))
1917

2018
// Try to run the unit tests.
2119
.then(() => ng('test', '--single-run'));
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import {join} from 'path';
22
import {ng} from '../../../utils/process';
33
import {expectFileToExist} from '../../../utils/fs';
4+
import {expectToFail} from '../../../utils/utils';
45

56

67
export default function() {
7-
const moduleDir = join('src', 'app', 'test-module');
8+
const moduleDir = join('src', 'app', 'test');
89

9-
return ng('generate', 'module', 'test-module', '--routing')
10+
return ng('generate', 'module', 'test', '--routing')
1011
.then(() => expectFileToExist(moduleDir))
11-
.then(() => expectFileToExist(join(moduleDir, 'test-module.module.ts')))
12-
.then(() => expectFileToExist(join(moduleDir, 'test-module-routing.module.ts')))
13-
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.ts')))
14-
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.spec.ts')))
15-
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.html')))
16-
.then(() => expectFileToExist(join(moduleDir, 'test-module.component.css')))
17-
12+
.then(() => expectFileToExist(join(moduleDir, 'test.module.ts')))
13+
.then(() => expectFileToExist(join(moduleDir, 'test-routing.module.ts')))
14+
.then(() => expectFileToExist(join(moduleDir, 'test.component.ts')))
15+
.then(() => expectFileToExist(join(moduleDir, 'test.component.spec.ts')))
16+
.then(() => expectFileToExist(join(moduleDir, 'test.component.html')))
17+
.then(() => expectFileToExist(join(moduleDir, 'test.component.css')))
18+
.then(() => expectToFail(() => expectFileToExist(join(moduleDir, 'test.spec.ts'))))
1819
// Try to run the unit tests.
1920
.then(() => ng('test', '--single-run'));
2021
}

0 commit comments

Comments
 (0)