diff --git a/server/test/setup.ts b/server/test/setup.ts new file mode 100644 index 0000000..4bb1fa8 --- /dev/null +++ b/server/test/setup.ts @@ -0,0 +1,22 @@ +import { mkdtempSync, rmSync } from 'node:fs' +import { tmpdir } from 'node:os' +import { join } from 'node:path' +import { afterAll, beforeAll } from 'vitest' +import { closeDb } from '../utils/db' + +const workerId = process.env.VITEST_POOL_ID ?? String(process.pid) +const dataDir = mkdtempSync(join(tmpdir(), `pichost-test-${workerId}-`)) +process.env.DATA_DIR = dataDir + +beforeAll(() => { + closeDb() +}) + +afterAll(() => { + closeDb() + try { + rmSync(dataDir, { recursive: true, force: true }) + } catch { + // Windows may still hold the sqlite file for a moment after close + } +}) diff --git a/server/utils/host-isolation.test.ts b/server/utils/host-isolation.test.ts index d06aa8f..9926759 100644 --- a/server/utils/host-isolation.test.ts +++ b/server/utils/host-isolation.test.ts @@ -131,7 +131,8 @@ describe('shouldBlockSiteHostImageRequest', () => { siteHost, requestHost: siteHost, method: 'GET', - pathname: '/' + pathname: '/', + hideFolder: false })).toBe(false) }) diff --git a/vitest.config.ts b/vitest.config.ts index 6a49674..2289f92 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -3,6 +3,8 @@ import { defineConfig } from 'vitest/config' export default defineConfig({ test: { environment: 'node', - include: ['server/**/*.test.ts'] + include: ['server/**/*.test.ts'], + pool: 'forks', + setupFiles: ['./server/test/setup.ts'] } })