-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvitest.config.ts
More file actions
138 lines (134 loc) · 4.57 KB
/
vitest.config.ts
File metadata and controls
138 lines (134 loc) · 4.57 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/**
* Vitest Configuration
*
* Unit test configuration
* - React component tests
* - Redux slice tests
* - Utility function tests
*/
import { fileURLToPath } from 'node:url'
import path from 'path'
import { storybookTest } from '@storybook/addon-vitest/vitest-plugin'
import react from '@vitejs/plugin-react'
import { playwright } from '@vitest/browser-playwright'
import { loadEnv } from 'vite'
import { defineConfig } from 'vitest/config'
const dirname =
typeof __dirname !== 'undefined'
? __dirname
: path.dirname(fileURLToPath(import.meta.url))
// More info at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon
export default defineConfig(({ mode }) => ({
plugins: [react()],
// Pre-bundle dependencies to prevent Vite re-optimization during tests
optimizeDeps: {
include: ['superjson', 'lz-string'],
},
test: {
// Transform packages through Vite's module runner for compatibility
server: {
deps: {
// Process these packages through Vite for CSS compatibility
// - @platejs/math: imports katex CSS that needs Vite's CSS handling
inline: ['@platejs/math'],
},
},
// Load environment variables from .env.test (mode defaults to 'test' in vitest)
// Empty prefix '' loads ALL env vars, not just VITE_* prefixed ones
env: loadEnv(mode, process.cwd(), ''),
// Shared configuration
globals: true,
coverage: {
// V8 is stable for CI, Istanbul supports browser mode (Storybook) but has CI issues
// Use VITEST_COVERAGE_PROVIDER=istanbul locally to include Storybook coverage
provider:
(process.env.VITEST_COVERAGE_PROVIDER as 'v8' | 'istanbul') || 'v8',
reporter: ['text', 'json', 'lcov', 'html'],
exclude: [
'node_modules/',
'src/tests/',
'*.config.ts',
'*.config.js',
'.next/',
'dist/',
// Supabase-related files (DB communication - tested via integration tests)
'src/lib/actions/**',
'src/lib/supabase/**',
// CSS files (not testable via code coverage)
'src/styles/**',
// MSW mock handlers (test utilities, not production code)
'mocks/**',
// SVG icon definitions (no logic to test)
'src/components/ui/table-icons.tsx',
// App router pages (Server Components - tested via E2E)
'src/app/**/page.tsx',
'src/app/**/layout.tsx',
'src/app/**/route.ts',
'src/app/**/error.tsx',
'src/app/**/loading.tsx',
// MSW provider (test utility)
'src/app/msw-provider.tsx',
// Next.js proxy/middleware (tested via E2E)
'src/proxy.ts',
// Barrel files (only re-exports, no logic to test)
'**/index.ts',
// Type definition files
'**/*.d.ts',
],
},
// Two separate test projects: unit tests (happy-dom) and Storybook (browser)
projects: [
// Unit tests project (happy-dom environment - faster than jsdom)
{
extends: true,
test: {
name: 'unit',
environment: 'happy-dom',
include: [
'src/tests/unit/**/*.test.ts',
'src/tests/unit/**/*.test.tsx',
],
exclude: ['e2e/**/*', 'node_modules/**/*', 'dist/**/*'],
setupFiles: ['./src/tests/setup.ts'],
},
},
// Storybook tests project (browser environment with Playwright)
{
extends: true,
plugins: [
// The plugin will run tests for the stories defined in your Storybook config
// See options at: https://storybook.js.org/docs/next/writing-tests/integrations/vitest-addon#storybooktest
storybookTest({
configDir: path.join(dirname, '.storybook'),
// Script to start Storybook (--no-open prevents browser opening)
storybookScript: 'pnpm storybook --no-open',
}),
],
test: {
name: 'storybook',
browser: {
enabled: true,
headless: true,
provider: playwright({}),
instances: [
{
browser: 'chromium',
},
],
},
setupFiles: ['.storybook/vitest.setup.ts'],
},
},
],
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@/lib': path.resolve(__dirname, './src/lib'),
'@/components': path.resolve(__dirname, './src/components'),
'@/app': path.resolve(__dirname, './src/app'),
'@/styles': path.resolve(__dirname, './src/styles'),
'@/mocks': path.resolve(__dirname, './mocks'),
},
},
}))