mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-19 14:41:24 +08:00
fix: update vitest configuration and add setup file for renderer tests
- Updated vitest.config.ts to handle optional chaining for plugins and alias. - Added setup.ts for mocking electron-log in renderer tests. - Adjusted test include and exclude patterns to refine test coverage.
This commit is contained in:
parent
d091e3e9ee
commit
22295359e8
20
src/renderer/__tests__/setup.ts
Normal file
20
src/renderer/__tests__/setup.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { vi } from 'vitest'
|
||||
|
||||
vi.mock('electron-log/renderer', () => {
|
||||
return {
|
||||
default: {
|
||||
info: console.log,
|
||||
error: console.error,
|
||||
warn: console.warn,
|
||||
debug: console.debug,
|
||||
verbose: console.log,
|
||||
silly: console.log,
|
||||
log: console.log,
|
||||
transports: {
|
||||
console: {
|
||||
level: 'info'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -6,20 +6,22 @@ const rendererConfig = electronViteConfig.renderer
|
||||
|
||||
export default defineConfig({
|
||||
// 复用 renderer 插件和路径别名
|
||||
plugins: rendererConfig.plugins,
|
||||
// @ts-ignore plugins 类型
|
||||
plugins: rendererConfig?.plugins,
|
||||
resolve: {
|
||||
alias: rendererConfig.resolve.alias
|
||||
// @ts-ignore alias 类型
|
||||
alias: rendererConfig?.resolve.alias
|
||||
},
|
||||
test: {
|
||||
environment: 'jsdom',
|
||||
globals: true,
|
||||
setupFiles: [],
|
||||
setupFiles: ['./src/renderer/__tests__/setup.ts'],
|
||||
include: [
|
||||
// 只测试渲染进程
|
||||
'src/renderer/**/*.{test,spec}.{ts,tsx}',
|
||||
'src/renderer/**/__tests__/**/*.{ts,tsx}'
|
||||
],
|
||||
exclude: ['**/node_modules/**', '**/dist/**', '**/out/**', '**/build/**'],
|
||||
exclude: ['**/node_modules/**', '**/dist/**', '**/out/**', '**/build/**', '**/src/renderer/__tests__/setup.ts'],
|
||||
coverage: {
|
||||
provider: 'v8',
|
||||
reporter: ['text', 'json', 'html', 'lcov'],
|
||||
|
||||
Loading…
Reference in New Issue
Block a user