Skip to content

Commit a0ab547

Browse files
committed
test(@angular/cli): Add tests for running 'generate' in a subdirectory (#7135)
1 parent da1fc81 commit a0ab547

File tree

6 files changed

+93
-6
lines changed

6 files changed

+93
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1+
import * as fs from 'fs-extra';
12
import {join} from 'path';
23
import {ng} from '../../../utils/process';
34
import {expectFileToMatch} from '../../../utils/fs';
45

56

67
export default function() {
7-
const modulePath = join('src', 'app', 'app.module.ts');
8+
const root = process.cwd();
9+
const modulePath = join(root, 'src', 'app', 'app.module.ts');
10+
11+
fs.mkdirSync('./src/app/sub-dir');
812

913
return ng('generate', 'component', 'test-component', '--module', 'app.module.ts')
1014
.then(() => expectFileToMatch(modulePath,
1115
/import { TestComponentComponent } from '.\/test-component\/test-component.component'/))
1216

17+
.then(() => process.chdir(join(root, 'src', 'app')))
18+
.then(() => ng('generate', 'component', 'test-component2', '--module', 'app.module.ts'))
19+
.then(() => expectFileToMatch(modulePath,
20+
/import { TestComponent2Component } from '.\/test-component2\/test-component2.component'/))
21+
22+
.then(() => process.chdir(join(root, 'src', 'app', 'sub-dir')))
23+
.then(() => ng('generate', 'component', 'test-component3', '--module', 'app.module.ts'))
24+
.then(() => expectFileToMatch(modulePath,
25+
/import { TestComponent3Component } from '.\/test-component3\/test-component3.component'/))
26+
1327
// Try to run the unit tests.
1428
.then(() => ng('build'));
1529
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1+
import * as fs from 'fs-extra';
12
import {join} from 'path';
23
import {ng} from '../../../utils/process';
34
import {expectFileToMatch} from '../../../utils/fs';
45

56

67
export default function() {
7-
const modulePath = join('src', 'app', 'app.module.ts');
8+
const root = process.cwd();
9+
const modulePath = join(root, 'src', 'app', 'app.module.ts');
10+
11+
fs.mkdirSync('./src/app/sub-dir');
812

913
return ng('generate', 'directive', 'test-directive', '--module', 'app.module.ts')
1014
.then(() => expectFileToMatch(modulePath,
1115
/import { TestDirectiveDirective } from '.\/test-directive.directive'/))
1216

17+
.then(() => process.chdir(join(root, 'src', 'app')))
18+
.then(() => ng('generate', 'directive', 'test-directive2', '--module', 'app.module.ts'))
19+
.then(() => expectFileToMatch(modulePath,
20+
/import { TestDirective2Directive } from '.\/test-directive2.directive'/))
21+
22+
.then(() => process.chdir(join(root, 'src', 'app', 'sub-dir')))
23+
.then(() => ng('generate', 'directive', 'test-directive3', '--module', 'app.module.ts'))
24+
.then(() => expectFileToMatch(modulePath,
25+
/import { TestDirective3Directive } from '.\/test-directive3.directive'/))
26+
1327
// Try to run the unit tests.
1428
.then(() => ng('build'));
1529
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
1+
import * as fs from 'fs-extra';
12
import {join} from 'path';
23
import {ng} from '../../../utils/process';
34
import {expectFileToMatch} from '../../../utils/fs';
45

56

67
export default function() {
7-
const modulePath = join('src', 'app', 'app.module.ts');
8+
const root = process.cwd();
9+
const modulePath = join(root, 'src', 'app', 'app.module.ts');
10+
11+
fs.mkdirSync('./src/app/sub-dir');
812

913
return ng('generate', 'guard', 'test-guard', '--module', 'app.module.ts')
1014
.then(() => expectFileToMatch(modulePath,
1115
/import { TestGuardGuard } from '.\/test-guard.guard'/))
1216
.then(() => expectFileToMatch(modulePath,
1317
/providers:\s*\[TestGuardGuard\]/m))
18+
19+
.then(() => process.chdir(join(root, 'src', 'app')))
20+
.then(() => ng('generate', 'guard', 'test-guard2', '--module', 'app.module.ts'))
21+
.then(() => expectFileToMatch(modulePath,
22+
/import { TestGuard2Guard } from '.\/test-guard2.guard'/))
23+
24+
.then(() => process.chdir(join(root, 'src', 'app', 'sub-dir')))
25+
.then(() => ng('generate', 'guard', 'test-guard3', '--module', 'app.module.ts'))
26+
.then(() => expectFileToMatch(modulePath,
27+
/import { TestGuard3Guard } from '.\/test-guard3.guard'/))
28+
1429
.then(() => ng('build'));
1530
}

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

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
import * as fs from 'fs-extra';
12
import { join } from 'path';
23
import { ng } from '../../../utils/process';
34
import { expectFileToMatch } from '../../../utils/fs';
45

56
export default function () {
6-
const modulePath = join('src', 'app', 'app.module.ts');
7+
const root = process.cwd();
8+
const modulePath = join(root, 'src', 'app', 'app.module.ts');
79
const subModulePath = join('src', 'app', 'sub', 'sub.module.ts');
810
const deepSubModulePath = join('src', 'app', 'sub', 'deep', 'deep.module.ts');
911

12+
fs.mkdirSync('./src/app/sub-dir');
13+
1014
return Promise.resolve()
1115
.then(() => ng('generate', 'module', 'sub'))
1216
.then(() => ng('generate', 'module', 'sub/deep'))
@@ -40,4 +44,16 @@ export default function () {
4044
.then(() => expectFileToMatch(deepSubModulePath,
4145
/import { Test6Module } from '.\/..\/..\/test6\/test6.module'/))
4246
.then(() => expectFileToMatch(deepSubModulePath, /imports: \[(.|\s)*Test6Module(.|\s)*\]/m)));
47+
48+
.then(() => process.chdir(join(root, 'src', 'app')))
49+
.then(() => ng('generate', 'module', 'test7', '--module', 'app.module.ts')))
50+
.then(() => expectFileToMatch(modulePath,
51+
/import { Test7Module } from '.\/test7\/test7.module'/))
52+
.then(() => expectFileToMatch(modulePath, /imports: \[(.|\s)*Test7Module(.|\s)*\]/m))
53+
54+
.then(() => process.chdir(join(root, 'src', 'app', 'sub-dir')))
55+
.then(() => ng('generate', 'module', 'test8', '--module', 'app.module.ts')))
56+
.then(() => expectFileToMatch(modulePath,
57+
/import { Test8Module } from '.\/test8\/test8.module'/))
58+
.then(() => expectFileToMatch(modulePath, /imports: \[(.|\s)*Test8Module(.|\s)*\]/m))
4359
}
+15-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1+
import * as fs from 'fs-extra';
12
import {join} from 'path';
23
import {ng} from '../../../utils/process';
34
import {expectFileToMatch} from '../../../utils/fs';
45

56

67
export default function() {
7-
const modulePath = join('src', 'app', 'app.module.ts');
8+
const root = process.cwd();
9+
const modulePath = join(root, 'src', 'app', 'app.module.ts');
10+
11+
fs.mkdirSync('./src/app/sub-dir');
812

913
return ng('generate', 'pipe', 'test-pipe', '--module', 'app.module.ts')
1014
.then(() => expectFileToMatch(modulePath,
1115
/import { TestPipePipe } from '.\/test-pipe.pipe'/))
1216

17+
.then(() => process.chdir(join(root, 'src', 'app')))
18+
.then(() => ng('generate', 'pipe', 'test-pipe2', '--module', 'app.module.ts'))
19+
.then(() => expectFileToMatch(modulePath,
20+
/import { TestPipe2Pipe } from '.\/test-pipe2.pipe'/))
21+
22+
.then(() => process.chdir(join(root, 'src', 'app', 'sub-dir')))
23+
.then(() => ng('generate', 'pipe', 'test-pipe3', '--module', 'app.module.ts'))
24+
.then(() => expectFileToMatch(modulePath,
25+
/import { TestPipe3Pipe } from '.\/test-pipe3.pipe'/))
26+
1327
// Try to run the unit tests.
1428
.then(() => ng('build'));
1529
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1+
import * as fs from 'fs-extra';
12
import {join} from 'path';
23
import {ng} from '../../../utils/process';
34
import {expectFileToMatch} from '../../../utils/fs';
45

56

67
export default function() {
7-
const modulePath = join('src', 'app', 'app.module.ts');
8+
const root = process.cwd();
9+
const modulePath = join(root, 'src', 'app', 'app.module.ts');
10+
11+
fs.mkdirSync('./src/app/sub-dir');
812

913
return ng('generate', 'service', 'test-service', '--module', 'app.module.ts')
1014
.then(() => expectFileToMatch(modulePath,
1115
/import { TestServiceService } from '.\/test-service.service'/))
1216

17+
.then(() => process.chdir(join(root, 'src', 'app')))
18+
.then(() => ng('generate', 'service', 'test-service2', '--module', 'app.module.ts'))
19+
.then(() => expectFileToMatch(modulePath,
20+
/import { TestService2Service } from '.\/test-service2.service'/))
21+
22+
.then(() => process.chdir(join(root, 'src', 'app', 'sub-dir')))
23+
.then(() => ng('generate', 'service', 'test-service3', '--module', 'app.module.ts'))
24+
.then(() => expectFileToMatch(modulePath,
25+
/import { TestService3Service } from '.\/test-service3.service'/))
26+
1327
// Try to run the unit tests.
1428
.then(() => ng('build'));
1529
}

0 commit comments

Comments
 (0)