-
Notifications
You must be signed in to change notification settings - Fork 40
/
global-setup.ts
36 lines (30 loc) · 1021 Bytes
/
global-setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import 'reflect-metadata';
import { afterAll, beforeAll, vi } from 'vitest';
vi.mock('pino');
let rootDir!: string;
let cacheDir!: string;
beforeAll(async () => {
const fs =
await vi.importActual<typeof import('node:fs/promises')>(
'node:fs/promises',
);
const os = await vi.importActual<typeof import('node:os')>('node:os');
const path = await vi.importActual<typeof import('node:path')>('node:path');
cacheDir = globalThis.cacheDir = await fs.mkdtemp(
path.join(os.tmpdir(), 'containerbase-cache-'),
);
rootDir = globalThis.rootDir = await fs.mkdtemp(
path.join(os.tmpdir(), 'containerbase-root-'),
);
const { env } =
await vi.importActual<typeof import('node:process')>('node:process');
env.CONTAINERBASE_CACHE_DIR = globalThis.cacheDir;
});
afterAll(async () => {
const fs =
await vi.importActual<typeof import('node:fs/promises')>(
'node:fs/promises',
);
await fs.rm(cacheDir, { recursive: true });
await fs.rm(rootDir, { recursive: true });
});