fix: give each test worker its own SQLite database
Parallel Vitest workers were opening data/pichost.db together, so host-isolation failed with database is locked.
This commit is contained in:
1 parent
10baf9d489
commit
424bfd9090
3 files changed
+27
-2
No files matched your search
@@ -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
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -131,7 +131,8 @@ describe('shouldBlockSiteHostImageRequest', () => {
|
|||||||
siteHost,
|
siteHost,
|
||||||
requestHost: siteHost,
|
requestHost: siteHost,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
pathname: '/'
|
pathname: '/',
|
||||||
|
hideFolder: false
|
||||||
})).toBe(false)
|
})).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -3,6 +3,8 @@ import { defineConfig } from 'vitest/config'
|
|||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
test: {
|
test: {
|
||||||
environment: 'node',
|
environment: 'node',
|
||||||
include: ['server/**/*.test.ts']
|
include: ['server/**/*.test.ts'],
|
||||||
|
pool: 'forks',
|
||||||
|
setupFiles: ['./server/test/setup.ts']
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Reference in new issue
Block a user