mirror of
https://github.com/simstudioai/sim.git
synced 2026-02-01 10:14:56 -05:00
* feat(deployed-form): added deployed form input * styling consolidation, finishing touches on form * updated docs * remove unused files with knip * added more form fields * consolidated more test utils * remove unused/unneeded zustand stores, refactored stores for consistency * improvement(files): uncolorized plan name * feat(emcn): button-group * feat(emcn): tag input, tooltip shortcut * improvement(emcn): modal padding, api, chat, form * fix: deleted migrations * feat(form): added migrations * fix(emcn): tag input * fix: failing tests on build * add suplementary hover and fix bg color in date picker * fix: build errors --------- Co-authored-by: Emir Karabeg <emirkarabeg@berkeley.edu>
58 lines
1.5 KiB
Plaintext
58 lines
1.5 KiB
Plaintext
---
|
|
description: Testing patterns with Vitest and @sim/testing
|
|
globs: ["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' })
|
|
```
|