forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-module.spec.js
85 lines (72 loc) · 3.71 KB
/
generate-module.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
'use strict';
const ng = require('../helpers/ng');
const tmp = require('../helpers/tmp');
const existsSync = require('exists-sync');
const expect = require('chai').expect;
const path = require('path');
const root = process.cwd();
const testPath = path.join(root, 'tmp', 'foo', 'src', 'app');
describe('Acceptance: ng generate module', function () {
beforeEach(function () {
return tmp.setup('./tmp').then(function () {
process.chdir('./tmp');
}).then(function () {
return ng(['new', 'foo', '--skip-npm']);
});
});
afterEach(function () {
this.timeout(10000);
return tmp.teardown('./tmp');
});
it('will fail if no name is specified', function () {
return ng(['generate', 'module']).catch((error) => {
expect(error).to.equal('The `ng generate module` command requires a name to be specified.');
});
});
it('ng generate module my-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);
expect(existsSync(path.join(testPath, 'my-module', 'my-module.module.spec.ts'))).to.equal(true);
});
});
it('ng generate module TwoWord', function () {
return ng(['generate', 'module', 'TwoWord']).then(() => {
expect(existsSync(path.join(testPath, 'two-word', 'two-word.module.ts'))).to.equal(true);
expect(existsSync(path.join(testPath, 'two-word', 'two-word.module.spec.ts'))).to.equal(false);
});
});
it('ng generate module parent/child', function () {
return ng(['generate', 'module', 'parent']).then(() =>
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);
})
);
});
});