mirror of
https://github.com/simstudioai/sim.git
synced 2026-02-05 12:14:59 -05:00
* feat(claude): added rules * fix(copilot): chat loading; refactor(copilot): components, utils, hooks * fix(copilot): options selection strikethrough * fix(copilot): options render inside thinking * fix(copilot): checkpoints, user-input; improvement(code): colors * fix(copilot): scrolling, tool-call truncation, thinking ui * fix(copilot): tool call spacing and shimmer/actions on previous messages * improvement(copilot): queue * addressed comments
59 lines
1.5 KiB
Markdown
59 lines
1.5 KiB
Markdown
---
|
|
paths:
|
|
- "apps/sim/**/*.test.ts"
|
|
- "apps/sim/**/*.test.tsx"
|
|
---
|
|
|
|
# Testing Patterns
|
|
|
|
Use Vitest. Test files: `feature.ts` → `feature.test.ts`
|
|
|
|
## Structure
|
|
|
|
```typescript
|
|
/**
|
|
* @vitest-environment node
|
|
*/
|
|
import { databaseMock, loggerMock } from '@sim/testing'
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
|
|
vi.mock('@sim/db', () => databaseMock)
|
|
vi.mock('@sim/logger', () => loggerMock)
|
|
|
|
import { myFunction } from '@/lib/feature'
|
|
|
|
describe('myFunction', () => {
|
|
beforeEach(() => vi.clearAllMocks())
|
|
it.concurrent('isolated tests run in parallel', () => { ... })
|
|
})
|
|
```
|
|
|
|
## @sim/testing Package
|
|
|
|
Always prefer over local mocks.
|
|
|
|
| Category | Utilities |
|
|
|----------|-----------|
|
|
| **Mocks** | `loggerMock`, `databaseMock`, `setupGlobalFetchMock()` |
|
|
| **Factories** | `createSession()`, `createWorkflowRecord()`, `createBlock()`, `createExecutorContext()` |
|
|
| **Builders** | `WorkflowBuilder`, `ExecutionContextBuilder` |
|
|
| **Assertions** | `expectWorkflowAccessGranted()`, `expectBlockExecuted()` |
|
|
|
|
## Rules
|
|
|
|
1. `@vitest-environment node` directive at file top
|
|
2. `vi.mock()` calls before importing mocked modules
|
|
3. `@sim/testing` utilities over local mocks
|
|
4. `it.concurrent` for isolated tests (no shared mutable state)
|
|
5. `beforeEach(() => vi.clearAllMocks())` to reset state
|
|
|
|
## Hoisted Mocks
|
|
|
|
For mutable mock references:
|
|
|
|
```typescript
|
|
const mockFn = vi.hoisted(() => vi.fn())
|
|
vi.mock('@/lib/module', () => ({ myFunction: mockFn }))
|
|
mockFn.mockResolvedValue({ data: 'test' })
|
|
```
|