-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvitest.config.ts
More file actions
89 lines (77 loc) · 2.23 KB
/
Copy pathvitest.config.ts
File metadata and controls
89 lines (77 loc) · 2.23 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Vitest Configuration
*
* WHY VITEST:
* - Modern test runner with great developer experience
* - Native TypeScript and ESM support
* - Compatible with Cloudflare Workers runtime
* - Fast parallel execution
* - Built-in coverage reporting
*
* ALTERNATIVE CONSIDERED:
* Jest: More mature but slower and requires complex setup for ESM
*/
import { defineConfig } from 'vitest/config';
export default defineConfig({
resolve: {
alias: {
'cloudflare:workers': new URL('./tests/helpers/cloudflare-workers.ts', import.meta.url).pathname,
},
},
test: {
server: {
deps: {
inline: ['@cloudflare/workers-oauth-provider'],
},
},
// Test file patterns
include: ['src/**/*.test.ts', 'tests/unit/**/*.test.ts'],
exclude: ['node_modules', 'dist', '.wrangler'],
// Coverage configuration
coverage: {
// WHY V8:
// - Accurate source-level coverage
// - Fast instrumentation
// - Works well with TypeScript
provider: 'v8',
// Include all source files in coverage
include: ['src/**/*.ts'],
exclude: [
'src/**/*.test.ts',
'src/**/*.spec.ts',
'src/types.ts', // Type definitions don't need coverage
'src/index.ts', // Entry point, tested via integration tests
],
// Coverage thresholds
// WHY THESE NUMBERS:
// - 60% is achievable with current test suite
// - Gradually increase as more tests are added
// - Critical modules (auth, validation) should be 100%
thresholds: {
lines: 60,
functions: 60,
branches: 50,
statements: 60,
},
// Output formats
reporter: ['text', 'json', 'html'],
// Report uncovered lines
reportOnFailure: true,
},
// Test environment
// WHY NODE:
// Cloudflare Workers use V8 isolates, similar to Node.js
// We mock Workers-specific APIs (KV, etc.)
environment: 'node',
// Global test timeout
testTimeout: 10000, // 10 seconds
// Retry flaky tests
retry: 0, // Don't retry, fix flaky tests instead
// Reporter
reporters: ['verbose'],
// Mock reset behavior
clearMocks: true,
mockReset: true,
restoreMocks: true,
},
});