From e8879acb88a2d2e472aba4241c6211e6eed99d19 Mon Sep 17 00:00:00 2001 From: cexbrayat Date: Thu, 22 Aug 2019 20:14:42 +0200 Subject: [PATCH] fix(@schematics/angular): implements items type for guard schematics Fixes the type of the items in the `schema.json` for `implements`, as `enum` alone is not picked up by the CLI. Also migrates the existing e2e test to `async/await` and adds another one with `implements` to avoid regressions. --- packages/schematics/angular/guard/schema.json | 3 ++- .../e2e/tests/generate/guard/guard-basic.ts | 19 ++++++++----------- .../tests/generate/guard/guard-implements.ts | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 tests/legacy-cli/e2e/tests/generate/guard/guard-implements.ts diff --git a/packages/schematics/angular/guard/schema.json b/packages/schematics/angular/guard/schema.json index 64601452c5de..fa09334a80d3 100644 --- a/packages/schematics/angular/guard/schema.json +++ b/packages/schematics/angular/guard/schema.json @@ -59,7 +59,8 @@ "CanActivate", "CanActivateChild", "CanLoad" - ] + ], + "type": "string" }, "default": [ "CanActivate" diff --git a/tests/legacy-cli/e2e/tests/generate/guard/guard-basic.ts b/tests/legacy-cli/e2e/tests/generate/guard/guard-basic.ts index a30cfec2f310..7148fb0b5bf5 100644 --- a/tests/legacy-cli/e2e/tests/generate/guard/guard-basic.ts +++ b/tests/legacy-cli/e2e/tests/generate/guard/guard-basic.ts @@ -1,19 +1,16 @@ import {join} from 'path'; import {ng} from '../../../utils/process'; -import {expectFileToExist} from '../../../utils/fs'; +import {expectFileToExist, expectFileToMatch} from '../../../utils/fs'; -export default function() { +export default async function() { // Does not create a sub directory. const guardDir = join('src', 'app'); - return ng('generate', 'guard', 'test-guard') - .then(() => expectFileToExist(guardDir)) - .then(() => expectFileToExist(join(guardDir, 'test-guard.guard.ts'))) - .then(() => expectFileToExist(join(guardDir, 'test-guard.guard.spec.ts'))); - - - // Try to run the unit tests. - // TODO: Enable once schematic is updated for rxjs 6 - // .then(() => ng('test', '--watch=false')); + await ng('generate', 'guard', 'test-guard'); + await expectFileToExist(guardDir); + await expectFileToExist(join(guardDir, 'test-guard.guard.ts')); + await expectFileToMatch(join(guardDir, 'test-guard.guard.ts'), /implements CanActivate/); + await expectFileToExist(join(guardDir, 'test-guard.guard.spec.ts')); + await ng('test', '--watch=false'); } diff --git a/tests/legacy-cli/e2e/tests/generate/guard/guard-implements.ts b/tests/legacy-cli/e2e/tests/generate/guard/guard-implements.ts new file mode 100644 index 000000000000..5dcf2a32d18c --- /dev/null +++ b/tests/legacy-cli/e2e/tests/generate/guard/guard-implements.ts @@ -0,0 +1,16 @@ +import {join} from 'path'; +import {ng} from '../../../utils/process'; +import {expectFileToExist,expectFileToMatch} from '../../../utils/fs'; + + +export default async function() { + // Does not create a sub directory. + const guardDir = join('src', 'app'); + + await ng('generate', 'guard', 'load', '--implements=CanLoad'); + await expectFileToExist(guardDir); + await expectFileToExist(join(guardDir, 'load.guard.ts')); + await expectFileToMatch(join(guardDir, 'load.guard.ts'), /implements CanLoad/); + await expectFileToExist(join(guardDir, 'load.guard.spec.ts')); + await ng('test', '--watch=false'); +}