forked from miantiao-me/Sink
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.config.ts
More file actions
54 lines (50 loc) · 1.46 KB
/
Copy pathvitest.config.ts
File metadata and controls
54 lines (50 loc) · 1.46 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
53
54
import { cloudflareTest, readD1Migrations } from '@cloudflare/vitest-pool-workers'
import { loadEnv } from 'vite'
import { defineConfig } from 'vitest/config'
interface HandledValidationError {
statusCode: 400
statusMessage: 'Validation Error'
data: {
issues: unknown[]
name: 'ZodError'
stack: string
}
}
function isHandledValidationError(error: unknown): error is HandledValidationError {
if (typeof error !== 'object' || error === null
|| !('statusCode' in error) || error.statusCode !== 400
|| !('statusMessage' in error) || error.statusMessage !== 'Validation Error'
|| !('data' in error) || typeof error.data !== 'object' || error.data === null) {
return false
}
const { data } = error
return 'issues' in data && Array.isArray(data.issues)
&& 'name' in data && data.name === 'ZodError'
&& 'stack' in data && typeof data.stack === 'string'
&& data.stack.includes('validateData')
}
export default defineConfig(async ({ mode }) => ({
plugins: [
cloudflareTest({
wrangler: {
configPath: './wrangler.jsonc',
},
miniflare: {
cf: true,
bindings: {
TEST_MIGRATIONS: await readD1Migrations('./drizzle'),
},
},
}),
],
test: {
env: loadEnv(mode, process.cwd(), ''),
isolate: false,
maxWorkers: 1,
setupFiles: ['./tests/setup.ts'],
testTimeout: 10_000,
onUnhandledError(error) {
return !isHandledValidationError(error)
},
},
}))