diff --git a/src/cdk/schematics/ng-update/test-cases/misc/method-call-checks.spec.ts b/src/cdk/schematics/ng-update/test-cases/misc/method-call-checks.spec.ts index 37be49ece93..321acc289fb 100644 --- a/src/cdk/schematics/ng-update/test-cases/misc/method-call-checks.spec.ts +++ b/src/cdk/schematics/ng-update/test-cases/misc/method-call-checks.spec.ts @@ -4,7 +4,7 @@ import {runTestCases} from '../../../testing'; describe('v6 method call checks', () => { it('should properly report invalid method calls', async () => { - const {logOutput} = await runTestCases('migration-v6', migrationCollection, { + const {logOutput, removeTempDir} = await runTestCases('migration-v6', migrationCollection, { 'method-call-checks': require.resolve('./method-call-checks_input.ts') }); @@ -12,5 +12,7 @@ describe('v6 method call checks', () => { .toMatch(/\[15,.*Found call to "FocusMonitor\.monitor".*renderer.*has been removed/); expect(logOutput) .toMatch(/\[16,.*Found call to "FocusMonitor\.monitor".*renderer.*has been removed/); + + removeTempDir(); }); }); diff --git a/src/cdk/schematics/ng-update/test-cases/v6-test-cases.spec.ts b/src/cdk/schematics/ng-update/test-cases/v6-test-cases.spec.ts index 5d0a68be683..613ccfdc2ac 100644 --- a/src/cdk/schematics/ng-update/test-cases/v6-test-cases.spec.ts +++ b/src/cdk/schematics/ng-update/test-cases/v6-test-cases.spec.ts @@ -16,6 +16,7 @@ describe('v6 upgrade test cases', () => { ]; let testCasesOutputPath: string; + let cleanupTestApp: () => void; beforeAll(async () => { const testCaseInputs = testCases.reduce((inputs, testCaseName) => { @@ -23,11 +24,15 @@ describe('v6 upgrade test cases', () => { return inputs; }, {} as {[name: string]: string}); - const {tempPath} = await runTestCases('migration-v6', migrationCollection, testCaseInputs); + const {tempPath, removeTempDir} = + await runTestCases('migration-v6', migrationCollection, testCaseInputs); testCasesOutputPath = join(tempPath, 'projects/cdk-testing/src/test-cases/'); + cleanupTestApp = removeTempDir; }); + afterAll(() => cleanupTestApp()); + // Iterates through every test case directory and generates a jasmine test block that will // verify that the update schematics properly updated the test input to the expected output. testCases.forEach(testCaseName => { diff --git a/src/cdk/schematics/ng-update/test-cases/v7-test-cases.spec.ts b/src/cdk/schematics/ng-update/test-cases/v7-test-cases.spec.ts index ab4d02b8dd5..0a01b3c48a2 100644 --- a/src/cdk/schematics/ng-update/test-cases/v7-test-cases.spec.ts +++ b/src/cdk/schematics/ng-update/test-cases/v7-test-cases.spec.ts @@ -13,6 +13,7 @@ describe('v7 upgrade test cases', () => { ]; let testCasesOutputPath: string; + let cleanupTestApp: () => void; beforeAll(async () => { const testCaseInputs = testCases.reduce((inputs, testCaseName) => { @@ -20,11 +21,15 @@ describe('v7 upgrade test cases', () => { return inputs; }, {} as {[name: string]: string}); - const {tempPath} = await runTestCases('migration-v7', migrationCollection, testCaseInputs); + const {tempPath, removeTempDir} = + await runTestCases('migration-v7', migrationCollection, testCaseInputs); testCasesOutputPath = join(tempPath, 'projects/cdk-testing/src/test-cases/'); + cleanupTestApp = removeTempDir; }); + afterAll(() => cleanupTestApp()); + // Iterates through every test case directory and generates a jasmine test block that will // verify that the update schematics properly updated the test input to the expected output. testCases.forEach(testCaseName => { diff --git a/src/cdk/schematics/testing/test-case-setup.ts b/src/cdk/schematics/testing/test-case-setup.ts index 9099d325d1a..9f1b31cf3fe 100644 --- a/src/cdk/schematics/testing/test-case-setup.ts +++ b/src/cdk/schematics/testing/test-case-setup.ts @@ -10,8 +10,8 @@ import {getSystemPath, normalize} from '@angular-devkit/core'; import {TempScopedNodeJsSyncHost} from '@angular-devkit/core/node/testing'; import * as virtualFs from '@angular-devkit/core/src/virtual-fs/host'; import {SchematicTestRunner} from '@angular-devkit/schematics/testing'; -import {readFileSync, writeFileSync, mkdirpSync} from 'fs-extra'; -import {join, dirname} from 'path'; +import {mkdirpSync, readFileSync, writeFileSync, removeSync} from 'fs-extra'; +import {dirname, join} from 'path'; import {createTestApp, runPostScheduledTasks} from '../testing'; /** Reads the UTF8 content of the specified file. Normalizes the path and ensures that */ @@ -34,7 +34,7 @@ export function createFileSystemTestApp(runner: SchematicTestRunner) { tempFileSystemHost.sync.write(f, virtualFs.stringToFileBuffer(appTree.readContent(f))); }); - return {appTree, tempPath}; + return {appTree, tempPath, removeTempDir: () => removeSync(tempPath)}; } export async function runTestCases(migrationName: string, collectionPath: string, @@ -47,7 +47,7 @@ export async function runTestCases(migrationName: string, collectionPath: string let logOutput = ''; runner.logger.subscribe(entry => logOutput += entry.message); - const {appTree, tempPath} = createFileSystemTestApp(runner); + const {appTree, tempPath, removeTempDir} = createFileSystemTestApp(runner); // Write each test-case input to the file-system. This is necessary because otherwise // TSLint won't be able to pick up the test cases. @@ -71,5 +71,5 @@ export async function runTestCases(migrationName: string, collectionPath: string // Switch back to the initial working directory. process.chdir(initialWorkingDir); - return {tempPath, logOutput}; + return {tempPath, logOutput, removeTempDir}; } diff --git a/src/lib/schematics/ng-update/test-cases/misc/constructor-checks.spec.ts b/src/lib/schematics/ng-update/test-cases/misc/constructor-checks.spec.ts index 9d3e0d391d7..fac8bd59591 100644 --- a/src/lib/schematics/ng-update/test-cases/misc/constructor-checks.spec.ts +++ b/src/lib/schematics/ng-update/test-cases/misc/constructor-checks.spec.ts @@ -4,7 +4,7 @@ import {runTestCases} from '@angular/cdk/schematics/testing'; describe('constructor checks', () => { it('should properly report invalid constructor expression signatures', async () => { - const {logOutput} = await runTestCases('migration-v6', migrationCollection, { + const {logOutput, removeTempDir} = await runTestCases('migration-v6', migrationCollection, { 'constructor-checks': require.resolve('./constructor-checks_input.ts') }); @@ -38,6 +38,8 @@ describe('constructor checks', () => { expect(logOutput).toMatch(/Found "ExtendedDateAdapter".*super.*: super\(string, Platform\)/); expect(logOutput).toMatch(/Found "ExtendedDateAdapter".*: new \w+\(string, Platform\)/); + + removeTempDir(); }); }); diff --git a/src/lib/schematics/ng-update/test-cases/misc/import-checks.spec.ts b/src/lib/schematics/ng-update/test-cases/misc/import-checks.spec.ts index f8b481cc232..300e798419f 100644 --- a/src/lib/schematics/ng-update/test-cases/misc/import-checks.spec.ts +++ b/src/lib/schematics/ng-update/test-cases/misc/import-checks.spec.ts @@ -4,12 +4,14 @@ import {migrationCollection} from '../index.spec'; describe('v6 import misc checks', () => { it('should report imports for deleted animation constants', async () => { - const {logOutput} = await runTestCases('migration-v6', migrationCollection, { + const {logOutput, removeTempDir} = await runTestCases('migration-v6', migrationCollection, { 'import-checks': require.resolve('./import-checks_input.ts') }); expect(logOutput).toMatch(/Found deprecated symbol "SHOW_ANIMATION"/); expect(logOutput).toMatch(/Found deprecated symbol "HIDE_ANIMATION"/); + + removeTempDir(); }); }); diff --git a/src/lib/schematics/ng-update/test-cases/v6-test-cases.spec.ts b/src/lib/schematics/ng-update/test-cases/v6-test-cases.spec.ts index d9f09c0fc1a..2d5ba197496 100644 --- a/src/lib/schematics/ng-update/test-cases/v6-test-cases.spec.ts +++ b/src/lib/schematics/ng-update/test-cases/v6-test-cases.spec.ts @@ -19,6 +19,7 @@ describe('v6 upgrade test cases', () => { ]; let testCasesOutputPath: string; + let cleanupTestApp: () => void; beforeAll(async () => { const testCaseInputs = testCases.reduce((inputs, testCaseName) => { @@ -26,11 +27,15 @@ describe('v6 upgrade test cases', () => { return inputs; }, {} as {[name: string]: string}); - const {tempPath} = await runTestCases('migration-v6', migrationCollection, testCaseInputs); + const {tempPath, removeTempDir} = + await runTestCases('migration-v6', migrationCollection, testCaseInputs); testCasesOutputPath = join(tempPath, 'projects/cdk-testing/src/test-cases/'); + cleanupTestApp = removeTempDir; }); + afterAll(() => cleanupTestApp()); + // Iterates through every test case directory and generates a jasmine test block that will // verify that the update schematics properly updated the test input to the expected output. testCases.forEach(testCaseName => { diff --git a/src/lib/schematics/ng-update/test-cases/v7-test-cases.spec.ts b/src/lib/schematics/ng-update/test-cases/v7-test-cases.spec.ts index 1c340f70307..b66b76537d8 100644 --- a/src/lib/schematics/ng-update/test-cases/v7-test-cases.spec.ts +++ b/src/lib/schematics/ng-update/test-cases/v7-test-cases.spec.ts @@ -14,6 +14,7 @@ describe('v7 upgrade test cases', () => { ]; let testCasesOutputPath: string; + let cleanupTestApp: () => void; beforeAll(async () => { const testCaseInputs = testCases.reduce((inputs, testCaseName) => { @@ -21,11 +22,15 @@ describe('v7 upgrade test cases', () => { return inputs; }, {} as {[name: string]: string}); - const {tempPath} = await runTestCases('migration-v7', migrationCollection, testCaseInputs); + const {tempPath, removeTempDir} = + await runTestCases('migration-v7', migrationCollection, testCaseInputs); testCasesOutputPath = join(tempPath, 'projects/cdk-testing/src/test-cases/'); + cleanupTestApp = removeTempDir; }); + afterAll(() => cleanupTestApp()); + // Iterates through every test case directory and generates a jasmine test block that will // verify that the update schematics properly updated the test input to the expected output. testCases.forEach(testCaseName => {