-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.workers.config.ts
More file actions
52 lines (49 loc) · 1.82 KB
/
vitest.workers.config.ts
File metadata and controls
52 lines (49 loc) · 1.82 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { defineConfig } from 'vitest/config';
import { cloudflarePool, cloudflareTest, readD1Migrations } from '@cloudflare/vitest-pool-workers';
import path from 'node:path';
// Apply schema migrations only — data migrations (seed/transfer/enrich) reference
// production-specific identities (e.g. real user IDs) and can't run on a clean
// test DB. Tests should seed their own data fixtures.
const allMigrations = await readD1Migrations('./migrations');
const isDml = (q: string) => /^\s*(INSERT|UPDATE|DELETE)\b/i.test(q);
const isDataOnlyMigration = (m: { queries: string[] }) => m.queries.length > 0 && m.queries.every(isDml);
const schemaMigrations = allMigrations.filter((m) => !isDataOnlyMigration(m));
const workersOptions = {
singleWorker: true,
miniflare: {
compatibilityDate: '2025-01-01',
compatibilityFlags: ['nodejs_compat'],
d1Databases: ['DB'],
bindings: {
TEST_MIGRATIONS: schemaMigrations,
JWT_SECRET: 'test-jwt-secret-key-32-chars-long',
APP_URL: 'http://localhost:5173'
}
}
};
export default defineConfig({
plugins: [cloudflareTest(workersOptions)],
test: {
include: [
'src/routes/api/health/**/*.test.ts',
'src/lib/server/auth.test.ts',
'src/lib/server/db/configs.test.ts',
'src/routes/api/configs/server.test.ts',
'src/routes/api/configs/[slug]/server.test.ts',
'src/routes/api/configs/[slug]/revisions/server.test.ts',
'src/routes/api/auth/cli/poll/server.test.ts',
'src/routes/api/auth/cli/start/server.test.ts',
'src/routes/api/auth/cli/approve/server.test.ts',
'src/routes/[username]/[slug]/install/server.test.ts',
'src/routes/[username]/[slug]/config/server.test.ts',
'src/smoke-tests/**/*.test.ts'
],
setupFiles: ['./src/lib/test/apply-migrations.ts'],
pool: cloudflarePool(workersOptions)
},
resolve: {
alias: {
$lib: path.resolve('./src/lib')
}
}
});