Files
cherry-studio/vitest.config.ts
Phantom 5167c927be fix: preserve openrouter reasoning with web search (#11505)
* feat(options): implement deep merging for provider options

Add deep merge functionality to preserve nested properties when combining provider options. The new implementation handles object merging recursively while maintaining type safety.

* refactor(tsconfig): reorganize include paths in tsconfig files

Clean up and reorder include paths for better maintainability and consistency between tsconfig.node.json and tsconfig.web.json

* test: add aiCore test configuration and script

Add new test configuration for aiCore package and corresponding test script in package.json to enable running tests specifically for the aiCore module.

* fix: format

* fix(aiCore): resolve test failures and update test infrastructure

- Add vitest setup file with global mocks for @cherrystudio/ai-sdk-provider
- Fix context assertions: use 'model' instead of 'modelId' in plugin tests
- Fix error handling tests: update expected error messages to match actual behavior
- Fix streamText tests: use 'maxOutputTokens' instead of 'maxTokens'
- Fix schemas test: update expected provider list to match actual implementation
- Fix mock-responses: use AI SDK v5 format (inputTokens/outputTokens)
- Update vi.mock to use importOriginal for preserving jsonSchema export

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(aiCore): add alias mock for @cherrystudio/ai-sdk-provider in tests

The vi.mock in setup file doesn't work for source code imports.
Use vitest resolve.alias to mock the external package properly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(aiCore): disable unused-vars warnings in mock file

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(aiCore): use import.meta.url for ESM compatibility in vitest config

__dirname is not available in ESM modules, use fileURLToPath instead.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(aiCore): use absolute paths in vitest config for workspace compatibility

- Use path.resolve for setupFiles and all alias paths
- Extend aiCore vitest.config.ts from root workspace config
- Change aiCore test environment to 'node' instead of 'jsdom'

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* docs(factory): improve mergeProviderOptions documentation

Add detailed explanation of merge behavior with examples

* test(factory): add tests for mergeProviderOptions behavior

Add test cases to verify mergeProviderOptions correctly handles primitive values, arrays, and nested objects during merging

* refactor(tests): clean up mock responses test fixtures

Remove unused mock streaming chunks and error responses to simplify test fixtures
Update warning details structure in mock complete responses

* docs(test): clarify comment in generateImage test

Update comment to use consistent 'model id' terminology instead of 'modelId'

* test(factory): verify array replacement in mergeProviderOptions

---------

Co-authored-by: suyao <sy20010504@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>
2025-11-28 13:56:46 +08:00

96 lines
2.6 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}'
]
}
}
],
// 全局共享配置
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
}
}
}
})