Skip to content

Commit 50c957b

Browse files
andrewkwwhansl
authored andcommitted
test: Add tests for running 'generate' in a subdirectory (#7135) (#7284)
1 parent 8632b10 commit 50c957b

File tree

6 files changed

+62
-6
lines changed

6 files changed

+62
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
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+
1322
// Try to run the unit tests.
1423
.then(() => ng('build'));
1524
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
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+
1322
// Try to run the unit tests.
1423
.then(() => ng('build'));
1524
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
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+
1424
.then(() => ng('build'));
1525
}

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

+11-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'))
@@ -42,4 +46,10 @@ export default function () {
4246
.then(() => expectFileToMatch(deepSubModulePath,
4347
/import { Test6Module } from '..\/..\/test6\/test6.module'/))
4448
.then(() => expectFileToMatch(deepSubModulePath, /imports: \[(.|\s)*Test6Module(.|\s)*\]/m)));
49+
50+
.then(() => process.chdir(join(root, 'src', 'app')))
51+
.then(() => ng('generate', 'module', 'test7', '--module', 'app.module.ts')))
52+
.then(() => expectFileToMatch(modulePath,
53+
/import { Test7Module } from '.\/test7\/test7.module'/))
54+
.then(() => expectFileToMatch(modulePath, /imports: \[(.|\s)*Test7Module(.|\s)*\]/m))
4555
}
+10-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
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+
1322
// Try to run the unit tests.
1423
.then(() => ng('build'));
1524
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
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+
1322
// Try to run the unit tests.
1423
.then(() => ng('build'));
1524
}

0 commit comments

Comments
 (0)