frontend/config/vitest-config/README.md
Shared Vitest configuration for the Coze architecture ecosystem
A unified testing configuration package that provides optimized Vitest setups for Node.js and web applications in the Coze monorepo. This package simplifies test configuration management and ensures consistency across all projects.
default, node, and web environmentsvite-tsconfig-pathsAdd the package to your project:
# In your package.json
{
"devDependencies": {
"@coze-arch/vitest-config": "workspace:*"
}
}
Then run:
rush update
Create a vitest.config.ts file in your project root:
import { defineConfig } from '@coze-arch/vitest-config';
export default defineConfig({
dirname: __dirname,
preset: 'web', // or 'node' or 'default'
});
defineConfig(config, otherConfig?)The main configuration function that creates a Vitest configuration based on your requirements.
config (VitestConfig):
dirname (string, required): The project root directory (__dirname)preset (string, required): Configuration preset - 'default' | 'node' | 'web'otherConfig (OtherConfig, optional):
fixSemi (boolean): Enable Semi Design component compatibility fixesDefault Configuration:
import { defineConfig } from '@coze-arch/vitest-config';
export default defineConfig({
dirname: __dirname,
preset: 'default',
});
Node.js Application:
import { defineConfig } from '@coze-arch/vitest-config';
export default defineConfig({
dirname: __dirname,
preset: 'node',
test: {
include: ['src/**/*.test.ts'],
exclude: ['src/**/*.browser.test.ts'],
},
});
React/Web Application:
import { defineConfig } from '@coze-arch/vitest-config';
export default defineConfig({
dirname: __dirname,
preset: 'web',
test: {
include: ['src/**/*.{test,spec}.{ts,tsx}'],
setupFiles: ['./src/test-setup.ts'],
},
});
With Semi Design Components:
import { defineConfig } from '@coze-arch/vitest-config';
export default defineConfig({
dirname: __dirname,
preset: 'web',
}, {
fixSemi: true,
});
Custom Coverage Configuration:
import { defineConfig } from '@coze-arch/vitest-config';
export default defineConfig({
dirname: __dirname,
preset: 'web',
test: {
coverage: {
all: true,
threshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80,
},
},
},
},
});
defaultnodewebhappy-dom environment for DOM testingTest Execution:
forks with 1-32 workersCoverage:
src/**/*.ts, src/**/*.tsxTypeScript:
vite-tsconfig-pathsmain, module, exports# Lint the code
rush lint
# Development mode
rush dev
src/
├── index.js # CommonJS entry point with Sucrase
├── define-config.ts # Main configuration function
├── preset-default.ts # Base configuration preset
├── preset-node.ts # Node.js specific preset
├── preset-web.ts # Web/React specific preset
└── tsc-only.ts # TypeScript-only mock file
vite-tsconfig-paths: TypeScript path mapping supportvitest: Core testing framework@vitejs/plugin-react: React support for web preset@vitest/coverage-v8: Coverage reportinghappy-dom: Lightweight DOM environmentsucrase: Fast TypeScript compilationThis package is part of the Coze architecture ecosystem and follows the project's licensing terms.