api: run the database tests serially again
Splitting the suite into projects moved fileParallelism into the project configs, where Vitest ignores it, so the database files ran in parallel and clobbered the one database they share. The option now sits at the root, where it is honored, and the whole suite is green again
Pedro Lucas Porcellis porcellis@eletrotupi.com · 10 days ago
7d05736f131f19302570c162dd01ea61962d392f Browse filesParents
aaca724Changed files
1
Additions
+11
Deletions
-7
api/vitest.config.ts
1 1
import { defineConfig } from 'vitest/config'
2 2
import tsconfigPaths from 'vite-tsconfig-paths'
3 3
4 4
// Both projects import source through the same `@app/*` alias the app uses
5 5
const appPaths = () => tsconfigPaths({ projects: ['./tsconfig.test.json'] })
6 6
7 7
export default defineConfig({
8 8
test: {
9 +
// Every database test file truncates and repopulates the same database, so
10 +
// they must not overlap. This has to live at the root: a project's own
11 +
// `fileParallelism` is not honored, and the default (parallel) corrupts the
12 +
// shared database across files.
13 +
fileParallelism: false,
14 +
9 15
// Report-only: there is no threshold and CI does not gate on it. The point
10 16
// is a visible unit-versus-integration ratio, not a build-breaking number.
11 17
coverage: {
12 18
provider: 'v8',
13 19
reporter: ['text', 'html'],
14 20
include: ['src/**/*.ts'],
15 21
exclude: ['src/**/*.d.ts'],
16 22
},
23 +
17 24
projects: [
18 25
// Pure tests: a single function, no HTTP, no database. No global mocks,
19 -
// so files run in parallel and need no running stack. The token module
20 -
// reads its secret at import time and this project runs without dotenv,
21 -
// so the env carries it.
26 +
// so files need no running stack. The token module reads its secret at
27 +
// import time and this project runs without dotenv, so the env carries it.
22 28
{
23 29
plugins: [appPaths()],
24 30
test: {
25 31
name: 'unit',
26 32
environment: 'node',
27 33
include: ['tests/**/*.unit.test.ts'],
28 -
fileParallelism: true,
29 34
testTimeout: 15_000,
30 35
env: { JWT_SECRET: 'unit-test-secret' },
31 36
},
32 37
},
33 38
34 -
// Integration and job tests: real app and database, serial because every
35 -
// file shares one database. Excludes the unit files so none runs twice.
39 +
// Integration and job tests: real app and database. Excludes the unit
40 +
// files so none runs twice.
36 41
{
37 42
plugins: [appPaths()],
38 43
test: {
39 44
name: 'db',
40 45
environment: 'node',
41 46
include: ['tests/**/*.test.ts'],
42 47
exclude: ['**/node_modules/**', 'tests/**/*.unit.test.ts'],
43 48
setupFiles: ['./tests/setup.ts'],
44 -
fileParallelism: false,
45 49
testTimeout: 15_000,
46 50
typecheck: {
47 51
tsconfig: './tsconfig.test.json',
48 52
},
49 53
},
50 54
},
51 55
],
52 56
},
53 57
})