63 lines
1.7 KiB
TypeScript
Executable file
63 lines
1.7 KiB
TypeScript
Executable file
import { defineConfig } from 'vitest/config'
|
|
import { mergeConfig } from 'vite'
|
|
import type { UserConfig } from 'vite'
|
|
|
|
/**
|
|
* Base Vitest configuration shared across all presets
|
|
*
|
|
* Provides sensible defaults for:
|
|
* - Global test utilities (globals: true)
|
|
* - Timeout settings (10s default)
|
|
* - Thread pool configuration
|
|
* - Coverage reporting (v8 provider)
|
|
* - Standard exclusions
|
|
*/
|
|
export const baseConfig: UserConfig = {
|
|
test: {
|
|
globals: true,
|
|
testTimeout: 10000,
|
|
pool: 'threads',
|
|
isolate: true,
|
|
coverage: {
|
|
provider: 'v8',
|
|
reporter: ['text', 'json', 'html'],
|
|
exclude: [
|
|
'node_modules/**',
|
|
'dist/**',
|
|
'**/*.spec.ts',
|
|
'**/*.spec.tsx',
|
|
'**/*.test.ts',
|
|
'**/*.test.tsx',
|
|
'**/*.config.ts',
|
|
'**/*.config.js',
|
|
'**/*.d.ts',
|
|
],
|
|
},
|
|
},
|
|
}
|
|
|
|
/**
|
|
* Creates a vitest preset with base config merged with preset-specific config
|
|
*
|
|
* @param presetConfig - Preset-specific configuration (e.g., environment, plugins)
|
|
* @returns Factory function that accepts user overrides and returns Vitest config
|
|
*
|
|
* @example
|
|
* ```typescript
|
|
* const nodePreset = createPreset({
|
|
* test: { environment: 'node' }
|
|
* })
|
|
*
|
|
* // Usage:
|
|
* export default nodePreset() // Use defaults
|
|
* export default nodePreset({ test: { timeout: 20000 } }) // Override timeout
|
|
* ```
|
|
*/
|
|
export function createPreset(presetConfig: UserConfig) {
|
|
return (userConfig: UserConfig = {}) => {
|
|
// Merge in order: base -> preset -> user
|
|
// Later configs override earlier ones
|
|
const merged = mergeConfig(mergeConfig(baseConfig, presetConfig), userConfig)
|
|
return defineConfig(merged)
|
|
}
|
|
}
|