mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-17 01:25:36 -05:00
Cleanup generated test files and folders for Sql DB projects (#20862)
* Cleanup generated test files and folders * Add await to fix tests
This commit is contained in:
@@ -13,6 +13,7 @@ import should = require('should');
|
||||
import { AssertionError } from 'assert';
|
||||
import { Project } from '../models/project';
|
||||
import { Uri } from 'vscode';
|
||||
import { exists } from '../common/utils';
|
||||
|
||||
export async function shouldThrowSpecificError(block: Function, expectedMessage: string, details?: string) {
|
||||
let succeeded = false;
|
||||
@@ -47,12 +48,17 @@ export async function createTestDataSources(contents: string, folderPath?: strin
|
||||
}
|
||||
|
||||
export async function generateTestFolderPath(): Promise<string> {
|
||||
const folderPath = path.join(os.tmpdir(), 'ADS_Tests', `TestRun_${new Date().getTime()}`);
|
||||
const folderPath = path.join(generateBaseFolderName(), `TestRun_${new Date().getTime()}`);
|
||||
await fs.mkdir(folderPath, { recursive: true });
|
||||
|
||||
return folderPath;
|
||||
}
|
||||
|
||||
export function generateBaseFolderName(): string {
|
||||
const folderPath = path.join(os.tmpdir(), 'ADS_Tests');
|
||||
return folderPath;
|
||||
}
|
||||
|
||||
export async function createTestFile(contents: string, fileName: string, folderPath?: string): Promise<string> {
|
||||
folderPath = folderPath ?? await generateTestFolderPath();
|
||||
const filePath = path.join(folderPath, fileName);
|
||||
@@ -249,3 +255,14 @@ export async function createOtherDummyFiles(testFolderPath: string): Promise<Uri
|
||||
|
||||
return filesList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes folder generated for testing
|
||||
*/
|
||||
export async function deleteGeneratedTestFolder(): Promise<void> {
|
||||
const testFolderPath: string = generateBaseFolderName();
|
||||
if (await exists(testFolderPath)) {
|
||||
// cleanup folder
|
||||
await fs.rm(testFolderPath, { recursive: true });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user