Тесты: часть 1
This commit is contained in:
35
tests/helpers/setup.ts
Normal file
35
tests/helpers/setup.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
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 };
|
||||
}
|
||||
Reference in New Issue
Block a user