35 lines
915 B
TypeScript
35 lines
915 B
TypeScript
import { tmpdir } from 'os';
|
|
import { join } from 'path';
|
|
import { mkdtemp, rm } from 'fs/promises';
|
|
|
|
/**
|
|
* Создание временной директории для тестов
|
|
*/
|
|
export async function createTempDir(): Promise<string> {
|
|
const prefix = join(tmpdir(), 'api-codegen-test-');
|
|
return await mkdtemp(prefix);
|
|
}
|
|
|
|
/**
|
|
* Очистка временной директории
|
|
*/
|
|
export async function cleanupTempDir(dir: string): Promise<void> {
|
|
try {
|
|
await rm(dir, { recursive: true, force: true });
|
|
} catch (error) {
|
|
// Игнорируем ошибки при очистке
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Setup функция для beforeEach
|
|
*/
|
|
export async function setupTest(): Promise<{ tempDir: string; cleanup: () => Promise<void> }> {
|
|
const tempDir = await createTempDir();
|
|
|
|
const cleanup = async () => {
|
|
await cleanupTempDir(tempDir);
|
|
};
|
|
|
|
return { tempDir, cleanup };
|
|
} |