chore(schematics): cleanup temporary directory after test case run (#14447)

* Currently we run _multiple_ test cases for the schematics and create temporary directories in order to test them with TSLint. This pollutes the temporary directory because we don't remove the temporary directory afterwards.
This commit is contained in:
Paul Gschwendtner
2018-12-12 00:00:25 +01:00
committed by vivian-hu
parent 86c138a0b6
commit 3ad8b1a3af
8 changed files with 38 additions and 12 deletions
@@ -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();
});
});
@@ -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 => {
@@ -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 => {
@@ -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};
}
@@ -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();
});
});
@@ -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();
});
});
@@ -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 => {
@@ -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 => {