mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-10 07:19:02 +08:00
feat: add test mocks path alias for improved import management
- Introduced a new path alias '@test-mocks' in TypeScript configuration files to simplify the import of mock utilities across the project. - Updated relevant files to utilize the new alias, enhancing code readability and maintainability. - Enhanced the README for test mocks to document the new import path, providing clearer guidance for developers on using mock utilities.
This commit is contained in:
parent
61dddad22f
commit
11843e21d5
@ -26,7 +26,8 @@ export default defineConfig({
|
||||
'@shared': resolve('packages/shared'),
|
||||
'@logger': resolve('src/main/services/LoggerService'),
|
||||
'@mcp-trace/trace-core': resolve('packages/mcp-trace/trace-core'),
|
||||
'@mcp-trace/trace-node': resolve('packages/mcp-trace/trace-node')
|
||||
'@mcp-trace/trace-node': resolve('packages/mcp-trace/trace-node'),
|
||||
'@test-mocks': resolve('tests/__mocks__')
|
||||
}
|
||||
},
|
||||
build: {
|
||||
@ -112,7 +113,8 @@ export default defineConfig({
|
||||
'@cherrystudio/extension-table-plus': resolve('packages/extension-table-plus/src'),
|
||||
'@cherrystudio/ai-sdk-provider': resolve('packages/ai-sdk-provider/src'),
|
||||
'@cherrystudio/ui/icons': resolve('packages/ui/src/components/icons'),
|
||||
'@cherrystudio/ui': resolve('packages/ui/src')
|
||||
'@cherrystudio/ui': resolve('packages/ui/src'),
|
||||
'@test-mocks': resolve('tests/__mocks__')
|
||||
}
|
||||
},
|
||||
optimizeDeps: {
|
||||
|
||||
@ -14,7 +14,7 @@ vi.mock('@logger', () => ({
|
||||
|
||||
// Mock PreferenceService using the existing mock
|
||||
vi.mock('@data/PreferenceService', async () => {
|
||||
const { MockMainPreferenceServiceExport } = await import('../../../../tests/__mocks__/main/PreferenceService')
|
||||
const { MockMainPreferenceServiceExport } = await import('@test-mocks/main/PreferenceService')
|
||||
return MockMainPreferenceServiceExport
|
||||
})
|
||||
|
||||
@ -86,7 +86,7 @@ import { preferenceService } from '@data/PreferenceService'
|
||||
import { UpdateMirror } from '@shared/config/constant'
|
||||
import { app, net } from 'electron'
|
||||
|
||||
import { MockMainPreferenceServiceUtils } from '../../../../tests/__mocks__/main/PreferenceService'
|
||||
import { MockMainPreferenceServiceUtils } from '@test-mocks/main/PreferenceService'
|
||||
import AppUpdater from '../AppUpdater'
|
||||
|
||||
// Mock clientId for ConfigManager since it's not migrated yet
|
||||
|
||||
@ -43,6 +43,15 @@ Mocks are globally configured in setup files:
|
||||
- **Renderer**: `tests/renderer.setup.ts`
|
||||
- **Main**: `tests/main.setup.ts`
|
||||
|
||||
### Import Path Alias
|
||||
|
||||
Use `@test-mocks/*` to import mock utilities:
|
||||
|
||||
```typescript
|
||||
import { MockCacheUtils } from '@test-mocks/renderer/CacheService'
|
||||
import { MockMainCacheServiceUtils } from '@test-mocks/main/CacheService'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Renderer Mocks
|
||||
@ -89,7 +98,7 @@ Three-tier cache system with type-safe and casual (dynamic key) methods.
|
||||
|
||||
```typescript
|
||||
import { cacheService } from '@data/CacheService'
|
||||
import { MockCacheUtils } from 'tests/__mocks__/renderer/CacheService'
|
||||
import { MockCacheUtils } from '@test-mocks/renderer/CacheService'
|
||||
|
||||
describe('Cache', () => {
|
||||
beforeEach(() => MockCacheUtils.resetMocks())
|
||||
@ -133,7 +142,7 @@ HTTP client with subscriptions and retry configuration.
|
||||
|
||||
```typescript
|
||||
import { dataApiService } from '@data/DataApiService'
|
||||
import { MockDataApiUtils } from 'tests/__mocks__/renderer/DataApiService'
|
||||
import { MockDataApiUtils } from '@test-mocks/renderer/DataApiService'
|
||||
|
||||
describe('API', () => {
|
||||
beforeEach(() => MockDataApiUtils.resetMocks())
|
||||
@ -175,7 +184,7 @@ React hooks for data operations.
|
||||
|
||||
```typescript
|
||||
import { useQuery, useMutation } from '@data/hooks/useDataApi'
|
||||
import { MockUseDataApiUtils } from 'tests/__mocks__/renderer/useDataApi'
|
||||
import { MockUseDataApiUtils } from '@test-mocks/renderer/useDataApi'
|
||||
|
||||
describe('Hooks', () => {
|
||||
beforeEach(() => MockUseDataApiUtils.resetMocks())
|
||||
@ -261,7 +270,7 @@ Internal cache and cross-window shared cache.
|
||||
| Shared | `deleteShared` | `<K>(key: K) => boolean` |
|
||||
|
||||
```typescript
|
||||
import { MockMainCacheServiceUtils } from 'tests/__mocks__/main/CacheService'
|
||||
import { MockMainCacheServiceUtils } from '@test-mocks/main/CacheService'
|
||||
|
||||
beforeEach(() => MockMainCacheServiceUtils.resetMocks())
|
||||
|
||||
@ -283,7 +292,7 @@ API coordinator managing ApiServer and IpcAdapter.
|
||||
| `getApiServer` | `() => ApiServer` |
|
||||
|
||||
```typescript
|
||||
import { MockMainDataApiServiceUtils } from 'tests/__mocks__/main/DataApiService'
|
||||
import { MockMainDataApiServiceUtils } from '@test-mocks/main/DataApiService'
|
||||
|
||||
beforeEach(() => MockMainDataApiServiceUtils.resetMocks())
|
||||
|
||||
|
||||
@ -28,7 +28,8 @@
|
||||
"@types": ["./src/renderer/src/types/index.ts"],
|
||||
"@shared/*": ["./packages/shared/*"],
|
||||
"@mcp-trace/*": ["./packages/mcp-trace/*"],
|
||||
"@modelcontextprotocol/sdk/*": ["./node_modules/@modelcontextprotocol/sdk/dist/esm/*"]
|
||||
"@modelcontextprotocol/sdk/*": ["./node_modules/@modelcontextprotocol/sdk/dist/esm/*"],
|
||||
"@test-mocks/*": ["./tests/__mocks__/*"]
|
||||
},
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
|
||||
@ -34,8 +34,8 @@
|
||||
"@cherrystudio/ai-sdk-provider": ["./packages/ai-sdk-provider/src/index.ts"],
|
||||
"@cherrystudio/ui/icons": ["./packages/ui/src/components/icons/index.ts"],
|
||||
"@cherrystudio/ui": ["./packages/ui/src/index.ts"],
|
||||
"@cherrystudio/ui/*": ["./packages/ui/src/*"]
|
||||
|
||||
"@cherrystudio/ui/*": ["./packages/ui/src/*"],
|
||||
"@test-mocks/*": ["./tests/__mocks__/*"]
|
||||
},
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user