Testing
Testing guide for Arg0 Desktop.
Overview
This guide covers testing strategies, tools, and best practices for Arg0 Desktop.
Testing Structure
text
tests/
├── unit/ # Unit tests
│ ├── components/
│ │ ├── Chat.spec.ts
│ │ └── OpenClaw.spec.ts
│ └── utils/
│ └── supabase.spec.ts
├── integration/ # Integration tests
│ ├── pages/
│ │ ├── AgentPage.spec.ts
│ │ └── DashboardPage.spec.ts
│ └── api/
│ └── mcp.spec.ts
└── e2e/ # End-to-end tests
├── test-agent.spec.ts
├── test-workflow.spec.ts
└── test-ui.spec.ts
Unit Testing
Tools
- Jest: Testing framework
- React Testing Library: Component testing
- @testing-library/jest-dom: Custom matchers
Writing Unit Tests
typescript
import { render, screen } from '@testing-library/react'
import { describe, it, expect } from 'vitest'
import Chat from '@/components/Chat'
describe('Chat Component', () => {
it('renders chat input', () => {
render(<Chat />)
const input = screen.getByPlaceholderText('Type a message...')
expect(input).toBeInTheDocument()
})
it('sends message on submit', () => {
const mockSendMessage = vi.fn()
render(<Chat onSendMessage={mockSendMessage} />)
// Test implementation
})
})
Running Unit Tests
bash
# Run all unit tests
npm run test:unit
# Run specific test file
npm run test:unit -- Chat.spec.ts
# Run with coverage
npm run test:unit -- --coverage
Integration Testing
Tools
- Vitest: Testing framework
- Supabase Test: Database testing
- MSW: API mocking
Writing Integration Tests
typescript
import { describe, it, expect, beforeEach } from 'vitest'
import { render } from '@testing-library/react'
import AgentPage from '@/pages/AgentPage'
describe('AgentPage Integration', () => {
beforeEach(() => {
// Setup test environment
})
it('executes agent with tool', async () => {
const { getByText } = render(<AgentPage />)
// Test agent execution with MCP tool
})
})
Running Integration Tests
bash
# Run all integration tests
npm run test:integration
# Run specific test
npm run test:integration -- AgentPage.spec.ts
End-to-End Testing
Tools
- Playwright: E2E testing framework
- @playwright/test: Test runner
Writing E2E Tests
typescript
import { test, expect } from '@playwright/test'
test('agent execution flow', async ({ page }) => {
await page.goto('http://localhost:3004')
await page.click('[data-testid="agent-input"]')
await page.fill('[data-testid="agent-input"]', 'Test goal')
await page.click('[data-testid="run-agent"]')
await expect(page.locator('[data-testid="agent-status"]')).toHaveText('completed')
})
Running E2E Tests
bash
# Run all E2E tests
npm run test:e2e
# Run specific test
npm run test:e2e -- test-agent.spec.ts
# Run with UI
npm run test:e2e -- --ui
# Run in headed mode
npm run test:e2e -- --headed
Test Configuration
Playwright Config
typescript
// playwright.config.ts
import { defineConfig } from '@playwright/test'
export default defineConfig({
testDir: './tests/e2e',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
baseURL: 'http://localhost:3004',
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: { browserName: 'chromium' },
},
],
})
Vitest Config
typescript
// vitest.config.ts
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
environment: 'jsdom',
globals: true,
setupFiles: ['./tests/setup.ts'],
},
})
Testing Best Practices
Unit Tests
- Test individual functions and components
- Mock external dependencies
- Keep tests fast and isolated
- Test edge cases
- Use descriptive test names
Integration Tests
- Test component interactions
- Test API integrations
- Use test databases
- Mock external services
- Test error scenarios
E2E Tests
- Test critical user flows
- Test cross-browser compatibility
- Use realistic test data
- Test error handling
- Keep tests maintainable
Test Coverage
Coverage Goals
- Overall: 80%+ coverage
- Critical Paths: 90%+ coverage
- Components: 75%+ coverage
- Utilities: 90%+ coverage
Coverage Report
bash
# Generate coverage report
npm run test:coverage
# View coverage report
open coverage/index.html
Continuous Integration
GitHub Actions
yaml
# .github/workflows/test.yml
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: npm install
- run: npm run test:unit
- run: npm run test:e2e
Debugging Tests
Unit Test Debugging
bash
# Run tests in debug mode
npm run test:unit -- --debug
# Run specific test in debug mode
npm run test:unit -- --debug Chat.spec.ts
E2E Test Debugging
bash
# Run tests in debug mode
npm run test:e2e -- --debug
# Run with inspector
npm run test:e2e -- --debug --headed
Common Issues
Tests Timing Out
- Increase timeout in test config
- Check for slow operations
- Optimize test data
- Use appropriate wait strategies
Flaky Tests
- Add retries for flaky tests
- Improve test isolation
- Use deterministic test data
- Check for race conditions
Tests Failing in CI
- Check CI environment differences
- Ensure dependencies are installed
- Check for environment-specific code
- Add CI-specific configuration
Related Documentation
- Contributing - Contribution guide
- Architecture - System architecture
- Project Management - Project organization