mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 13:36:48 +00:00
26 lines
1.4 KiB
TypeScript
26 lines
1.4 KiB
TypeScript
// Global test setup — runs before every test file.
|
|
// Environment variables must be set before any module import so that
|
|
// config.ts, database.ts, etc. pick them up at import time. (Importing from
|
|
// 'vitest' itself is safe: it is externalized and pulls in no app modules.)
|
|
import { afterEach } from 'vitest';
|
|
|
|
// Fixed encryption key (64 hex chars = 32 bytes) for at-rest crypto in tests
|
|
process.env.ENCRYPTION_KEY = 'a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6a7b8c9d0e1f2a3b4c5d6a7b8c9d0e1f2';
|
|
process.env.NODE_ENV = 'test';
|
|
process.env.COOKIE_SECURE = 'false';
|
|
process.env.LOG_LEVEL = 'error'; // suppress info/debug logs in test output
|
|
|
|
// Several services fire notification sends as unawaited dynamic-import chains
|
|
// (`import('…/notificationService').then(({ send }) => send(…).catch(…))`).
|
|
// Give those chains one macrotask turn to settle after every test, while the
|
|
// suite's DB and the worker environment are still alive — otherwise the last
|
|
// test in a file can leave the chain pending into worker teardown ("Cannot
|
|
// load ... after the environment was torn down"). Under the default "stack"
|
|
// hook order this afterEach runs after each test's own afterEach and before
|
|
// the suite's afterAll, i.e. before any afterAll closes its test DB.
|
|
// setImmediate is captured up front because some suites install fake timers.
|
|
const realSetImmediate = globalThis.setImmediate;
|
|
afterEach(async () => {
|
|
await new Promise((resolve) => realSetImmediate(resolve));
|
|
});
|