From 381468372bfecd4e6c2ca24d34827ba598004dd3 Mon Sep 17 00:00:00 2001 From: Andrew Wong Date: Tue, 8 Aug 2017 01:22:45 -0400 Subject: [PATCH] test(@angular/cli): Add tests for running 'generate' in a subdirectory (#7135) --- .../e2e/tests/generate/component/component-module.ts | 11 ++++++++++- .../e2e/tests/generate/directive/directive-module.ts | 11 ++++++++++- tests/e2e/tests/generate/guard/guard-module.ts | 12 +++++++++++- tests/e2e/tests/generate/module/module-import.ts | 12 +++++++++++- tests/e2e/tests/generate/pipe/pipe-module.ts | 11 ++++++++++- tests/e2e/tests/generate/service/service-module.ts | 11 ++++++++++- 6 files changed, 62 insertions(+), 6 deletions(-) diff --git a/tests/e2e/tests/generate/component/component-module.ts b/tests/e2e/tests/generate/component/component-module.ts index 4cbda4b5d07e..e742a1ecabeb 100644 --- a/tests/e2e/tests/generate/component/component-module.ts +++ b/tests/e2e/tests/generate/component/component-module.ts @@ -1,15 +1,24 @@ +import * as fs from 'fs-extra'; import {join} from 'path'; import {ng} from '../../../utils/process'; import {expectFileToMatch} from '../../../utils/fs'; export default function() { - const modulePath = join('src', 'app', 'app.module.ts'); + const root = process.cwd(); + const modulePath = join(root, 'src', 'app', 'app.module.ts'); + + fs.mkdirSync('./src/app/sub-dir'); return ng('generate', 'component', 'test-component', '--module', 'app.module.ts') .then(() => expectFileToMatch(modulePath, /import { TestComponentComponent } from '.\/test-component\/test-component.component'/)) + .then(() => process.chdir(join(root, 'src', 'app'))) + .then(() => ng('generate', 'component', 'test-component2', '--module', 'app.module.ts')) + .then(() => expectFileToMatch(modulePath, + /import { TestComponent2Component } from '.\/test-component2\/test-component2.component'/)) + // Try to run the unit tests. .then(() => ng('build')); } diff --git a/tests/e2e/tests/generate/directive/directive-module.ts b/tests/e2e/tests/generate/directive/directive-module.ts index c95637762896..2667c390c910 100644 --- a/tests/e2e/tests/generate/directive/directive-module.ts +++ b/tests/e2e/tests/generate/directive/directive-module.ts @@ -1,15 +1,24 @@ +import * as fs from 'fs-extra'; import {join} from 'path'; import {ng} from '../../../utils/process'; import {expectFileToMatch} from '../../../utils/fs'; export default function() { - const modulePath = join('src', 'app', 'app.module.ts'); + const root = process.cwd(); + const modulePath = join(root, 'src', 'app', 'app.module.ts'); + + fs.mkdirSync('./src/app/sub-dir'); return ng('generate', 'directive', 'test-directive', '--module', 'app.module.ts') .then(() => expectFileToMatch(modulePath, /import { TestDirectiveDirective } from '.\/test-directive.directive'/)) + .then(() => process.chdir(join(root, 'src', 'app'))) + .then(() => ng('generate', 'directive', 'test-directive2', '--module', 'app.module.ts')) + .then(() => expectFileToMatch(modulePath, + /import { TestDirective2Directive } from '.\/test-directive2.directive'/)) + // Try to run the unit tests. .then(() => ng('build')); } diff --git a/tests/e2e/tests/generate/guard/guard-module.ts b/tests/e2e/tests/generate/guard/guard-module.ts index 7ead4bdd903d..8718fdd700ae 100644 --- a/tests/e2e/tests/generate/guard/guard-module.ts +++ b/tests/e2e/tests/generate/guard/guard-module.ts @@ -1,15 +1,25 @@ +import * as fs from 'fs-extra'; import {join} from 'path'; import {ng} from '../../../utils/process'; import {expectFileToMatch} from '../../../utils/fs'; export default function() { - const modulePath = join('src', 'app', 'app.module.ts'); + const root = process.cwd(); + const modulePath = join(root, 'src', 'app', 'app.module.ts'); + + fs.mkdirSync('./src/app/sub-dir'); return ng('generate', 'guard', 'test-guard', '--module', 'app.module.ts') .then(() => expectFileToMatch(modulePath, /import { TestGuardGuard } from '.\/test-guard.guard'/)) .then(() => expectFileToMatch(modulePath, /providers:\s*\[TestGuardGuard\]/m)) + + .then(() => process.chdir(join(root, 'src', 'app'))) + .then(() => ng('generate', 'guard', 'test-guard2', '--module', 'app.module.ts')) + .then(() => expectFileToMatch(modulePath, + /import { TestGuard2Guard } from '.\/test-guard2.guard'/)) + .then(() => ng('build')); } diff --git a/tests/e2e/tests/generate/module/module-import.ts b/tests/e2e/tests/generate/module/module-import.ts index 05ba3a8a1e3b..3cf65e729740 100644 --- a/tests/e2e/tests/generate/module/module-import.ts +++ b/tests/e2e/tests/generate/module/module-import.ts @@ -1,12 +1,16 @@ +import * as fs from 'fs-extra'; import { join } from 'path'; import { ng } from '../../../utils/process'; import { expectFileToMatch } from '../../../utils/fs'; export default function () { - const modulePath = join('src', 'app', 'app.module.ts'); + const root = process.cwd(); + const modulePath = join(root, 'src', 'app', 'app.module.ts'); const subModulePath = join('src', 'app', 'sub', 'sub.module.ts'); const deepSubModulePath = join('src', 'app', 'sub', 'deep', 'deep.module.ts'); + fs.mkdirSync('./src/app/sub-dir'); + return Promise.resolve() .then(() => ng('generate', 'module', 'sub')) .then(() => ng('generate', 'module', 'sub/deep')) @@ -42,4 +46,10 @@ export default function () { .then(() => expectFileToMatch(deepSubModulePath, /import { Test6Module } from '..\/..\/test6\/test6.module'/)) .then(() => expectFileToMatch(deepSubModulePath, /imports: \[(.|\s)*Test6Module(.|\s)*\]/m))); + + .then(() => process.chdir(join(root, 'src', 'app'))) + .then(() => ng('generate', 'module', 'test7', '--module', 'app.module.ts'))) + .then(() => expectFileToMatch(modulePath, + /import { Test7Module } from '.\/test7\/test7.module'/)) + .then(() => expectFileToMatch(modulePath, /imports: \[(.|\s)*Test7Module(.|\s)*\]/m)) } diff --git a/tests/e2e/tests/generate/pipe/pipe-module.ts b/tests/e2e/tests/generate/pipe/pipe-module.ts index 65d938e0223a..c77d2d056943 100644 --- a/tests/e2e/tests/generate/pipe/pipe-module.ts +++ b/tests/e2e/tests/generate/pipe/pipe-module.ts @@ -1,15 +1,24 @@ +import * as fs from 'fs-extra'; import {join} from 'path'; import {ng} from '../../../utils/process'; import {expectFileToMatch} from '../../../utils/fs'; export default function() { - const modulePath = join('src', 'app', 'app.module.ts'); + const root = process.cwd(); + const modulePath = join(root, 'src', 'app', 'app.module.ts'); + + fs.mkdirSync('./src/app/sub-dir'); return ng('generate', 'pipe', 'test-pipe', '--module', 'app.module.ts') .then(() => expectFileToMatch(modulePath, /import { TestPipePipe } from '.\/test-pipe.pipe'/)) + .then(() => process.chdir(join(root, 'src', 'app'))) + .then(() => ng('generate', 'pipe', 'test-pipe2', '--module', 'app.module.ts')) + .then(() => expectFileToMatch(modulePath, + /import { TestPipe2Pipe } from '.\/test-pipe2.pipe'/)) + // Try to run the unit tests. .then(() => ng('build')); } diff --git a/tests/e2e/tests/generate/service/service-module.ts b/tests/e2e/tests/generate/service/service-module.ts index e13ea17f04e1..27723e9b6e69 100644 --- a/tests/e2e/tests/generate/service/service-module.ts +++ b/tests/e2e/tests/generate/service/service-module.ts @@ -1,15 +1,24 @@ +import * as fs from 'fs-extra'; import {join} from 'path'; import {ng} from '../../../utils/process'; import {expectFileToMatch} from '../../../utils/fs'; export default function() { - const modulePath = join('src', 'app', 'app.module.ts'); + const root = process.cwd(); + const modulePath = join(root, 'src', 'app', 'app.module.ts'); + + fs.mkdirSync('./src/app/sub-dir'); return ng('generate', 'service', 'test-service', '--module', 'app.module.ts') .then(() => expectFileToMatch(modulePath, /import { TestServiceService } from '.\/test-service.service'/)) + .then(() => process.chdir(join(root, 'src', 'app'))) + .then(() => ng('generate', 'service', 'test-service2', '--module', 'app.module.ts')) + .then(() => expectFileToMatch(modulePath, + /import { TestService2Service } from '.\/test-service2.service'/)) + // Try to run the unit tests. .then(() => ng('build')); }