mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-10 23:59:45 +08:00
* fix: prevent OOM when handling large base64 image data - Add memory-safe parseDataUrl utility using string operations instead of regex - Truncate large base64 data in ErrorBlock detail modal to prevent freezing - Update ImageViewer, FileStorage, messageConverter to use shared parseDataUrl - Deprecate parseDataUrlMediaType in favor of shared utility - Add GB support to formatFileSize - Add comprehensive unit tests for parseDataUrl (18 tests) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * refactor: simplify parseDataUrl API to return DataUrlParts | null - Change return type from discriminated union to simple nullable type - Update all call sites to use optional chaining (?.) - Update tests to use toBeNull() for failure cases - More idiomatic and consistent with codebase patterns (e.g., parseJSON) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
108 lines
2.9 KiB
TypeScript
108 lines
2.9 KiB
TypeScript
import { defineConfig } from 'vitest/config'
|
|
|
|
import electronViteConfig from './electron.vite.config'
|
|
|
|
const mainConfig = (electronViteConfig as any).main
|
|
const rendererConfig = (electronViteConfig as any).renderer
|
|
|
|
export default defineConfig({
|
|
test: {
|
|
projects: [
|
|
// 主进程单元测试配置
|
|
{
|
|
extends: true,
|
|
plugins: mainConfig.plugins,
|
|
resolve: {
|
|
alias: mainConfig.resolve.alias
|
|
},
|
|
test: {
|
|
name: 'main',
|
|
environment: 'node',
|
|
setupFiles: ['tests/main.setup.ts'],
|
|
include: ['src/main/**/*.{test,spec}.{ts,tsx}', 'src/main/**/__tests__/**/*.{test,spec}.{ts,tsx}']
|
|
}
|
|
},
|
|
// 渲染进程单元测试配置
|
|
{
|
|
extends: true,
|
|
plugins: rendererConfig.plugins.filter((plugin: any) => plugin.name !== 'tailwindcss'),
|
|
resolve: {
|
|
alias: rendererConfig.resolve.alias
|
|
},
|
|
test: {
|
|
name: 'renderer',
|
|
environment: 'jsdom',
|
|
setupFiles: ['@vitest/web-worker', 'tests/renderer.setup.ts'],
|
|
include: ['src/renderer/**/*.{test,spec}.{ts,tsx}', 'src/renderer/**/__tests__/**/*.{test,spec}.{ts,tsx}']
|
|
}
|
|
},
|
|
// 脚本单元测试配置
|
|
{
|
|
extends: true,
|
|
test: {
|
|
name: 'scripts',
|
|
environment: 'node',
|
|
include: ['scripts/**/*.{test,spec}.{ts,tsx}', 'scripts/**/__tests__/**/*.{test,spec}.{ts,tsx}']
|
|
}
|
|
},
|
|
// aiCore 包单元测试配置
|
|
{
|
|
extends: 'packages/aiCore/vitest.config.ts',
|
|
test: {
|
|
name: 'aiCore',
|
|
environment: 'node',
|
|
include: [
|
|
'packages/aiCore/**/*.{test,spec}.{ts,tsx}',
|
|
'packages/aiCore/**/__tests__/**/*.{test,spec}.{ts,tsx}'
|
|
]
|
|
}
|
|
},
|
|
// shared 包单元测试配置
|
|
{
|
|
extends: true,
|
|
test: {
|
|
name: 'shared',
|
|
environment: 'node',
|
|
include: [
|
|
'packages/shared/**/*.{test,spec}.{ts,tsx}',
|
|
'packages/shared/**/__tests__/**/*.{test,spec}.{ts,tsx}'
|
|
]
|
|
}
|
|
}
|
|
],
|
|
// 全局共享配置
|
|
globals: true,
|
|
setupFiles: [],
|
|
exclude: ['**/node_modules/**', '**/dist/**', '**/out/**', '**/build/**'],
|
|
coverage: {
|
|
provider: 'v8',
|
|
reporter: ['text', 'json', 'html', 'lcov', 'text-summary'],
|
|
exclude: [
|
|
'**/node_modules/**',
|
|
'**/dist/**',
|
|
'**/out/**',
|
|
'**/build/**',
|
|
'**/coverage/**',
|
|
'**/tests/**',
|
|
'**/.yarn/**',
|
|
'**/.cursor/**',
|
|
'**/.vscode/**',
|
|
'**/.github/**',
|
|
'**/.husky/**',
|
|
'**/*.d.ts',
|
|
'**/types/**',
|
|
'**/__tests__/**',
|
|
'**/*.{test,spec}.{ts,tsx}',
|
|
'**/*.config.{js,ts}'
|
|
]
|
|
},
|
|
testTimeout: 20000,
|
|
pool: 'threads',
|
|
poolOptions: {
|
|
threads: {
|
|
singleThread: false
|
|
}
|
|
}
|
|
}
|
|
})
|