Test Runner
Verified@cmanfre7
npx machina-cli add skill @cmanfre7/test-runner --openclawtest-runner
Write and run tests across languages and frameworks.
Framework Selection
| Language | Unit Tests | Integration | E2E |
|---|---|---|---|
| TypeScript/JS | Vitest (preferred), Jest | Supertest | Playwright |
| Python | pytest | pytest + httpx | Playwright |
| Swift | XCTest | XCTest | XCUITest |
Quick Start by Framework
Vitest (TypeScript / JavaScript)
npm install -D vitest @testing-library/react @testing-library/jest-dom
// vitest.config.ts
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
globals: true,
environment: 'jsdom',
setupFiles: './tests/setup.ts',
},
})
npx vitest # Watch mode
npx vitest run # Single run
npx vitest --coverage # With coverage
Jest
npm install -D jest @types/jest ts-jest
npx jest # Run all
npx jest --watch # Watch mode
npx jest --coverage # With coverage
npx jest path/to/test # Single file
pytest (Python)
uv pip install pytest pytest-cov pytest-asyncio httpx
pytest # Run all
pytest -v # Verbose
pytest -x # Stop on first failure
pytest --cov=app # With coverage
pytest tests/test_api.py -k "test_login" # Specific test
pytest --tb=short # Short tracebacks
XCTest (Swift)
swift test # Run all tests
swift test --filter MyTests # Specific test suite
swift test --parallel # Parallel execution
Playwright (E2E)
npm install -D @playwright/test
npx playwright install
npx playwright test # Run all
npx playwright test --headed # With browser visible
npx playwright test --debug # Debug mode
npx playwright test --project=chromium # Specific browser
npx playwright show-report # View HTML report
TDD Workflow
- Red — Write a failing test that describes the desired behavior.
- Green — Write the minimum code to make the test pass.
- Refactor — Clean up the code while keeping tests green.
┌─────────┐ ┌─────────┐ ┌──────────┐
│ Write │────▶│ Write │────▶│ Refactor │──┐
│ Test │ │ Code │ │ Code │ │
│ (Red) │ │ (Green) │ │ │ │
└─────────┘ └─────────┘ └──────────┘ │
▲ │
└──────────────────────────────────────────┘
Test Patterns
Arrange-Act-Assert
test('calculates total with tax', () => {
// Arrange
const cart = new Cart([{ price: 100, qty: 2 }]);
// Act
const total = cart.totalWithTax(0.08);
// Assert
expect(total).toBe(216);
});
Testing Async Code
test('fetches user data', async () => {
const user = await getUser('123');
expect(user.name).toBe('Colt');
});
Mocking
import { vi } from 'vitest';
const mockFetch = vi.fn().mockResolvedValue({
json: () => Promise.resolve({ id: 1, name: 'Test' }),
});
vi.stubGlobal('fetch', mockFetch);
Testing API Endpoints (Python)
import pytest
from httpx import AsyncClient
from app.main import app
@pytest.mark.asyncio
async def test_get_users():
async with AsyncClient(app=app, base_url="http://test") as client:
response = await client.get("/users")
assert response.status_code == 200
assert isinstance(response.json(), list)
Testing React Components
import { render, screen, fireEvent } from '@testing-library/react';
import { Button } from './Button';
test('calls onClick when clicked', () => {
const handleClick = vi.fn();
render(<Button onClick={handleClick}>Click me</Button>);
fireEvent.click(screen.getByText('Click me'));
expect(handleClick).toHaveBeenCalledOnce();
});
Coverage Commands
# JavaScript/TypeScript
npx vitest --coverage # Vitest (uses v8 or istanbul)
npx jest --coverage # Jest
# Python
pytest --cov=app --cov-report=html # HTML report
pytest --cov=app --cov-report=term # Terminal output
pytest --cov=app --cov-fail-under=80 # Fail if < 80%
# View HTML coverage report
open coverage/index.html # macOS
open htmlcov/index.html # Python
What to Test
Always test:
- Public API / exported functions
- Edge cases: empty input, null, boundary values
- Error handling: invalid input, network failures
- Business logic: calculations, state transitions
Don't bother testing:
- Private implementation details
- Framework internals (React rendering, Express routing)
- Trivial getters/setters
- Third-party library behavior
Overview
Test Runner lets you write and run unit, integration, and E2E tests across TypeScript, Python, and Swift using recommended frameworks. It maps languages to proven tools (Vitest/Jest for TS, pytest for Python, XCTest for Swift, and Playwright for E2E). The guide includes quick-start commands, test patterns, and a simple TDD workflow to keep tests fast and reliable.
How This Skill Works
The tool recommends framework mixes per language (TypeScript/JS: Vitest for unit, Supertest for integration, Playwright for E2E; Python: pytest for unit, pytest+httpx for API, Playwright for E2E; Swift: XCTest for unit and integration, XCUITest for E2E). It provides framework-specific quick-start blocks and example tests to scaffold your suite, along with common test patterns like Arrange-Act-Assert and async testing. A TDD Red-Green-Refactor workflow guides incremental improvements.
When to Use It
- Starting a new TS/JS, Python, or Swift project and selecting the recommended test framework
- Writing unit tests for core logic (e.g., TS cart totalWithTax) and API tests (e.g., Python /users) using the suggested patterns
- Creating end-to-end tests with Playwright to validate user flows
- Adopting the TDD workflow to drive feature development from Red to Green to Refactor
- Running tests locally or in CI with coverage reporting and HTML reports
Quick Start
- Step 1: Pick a language/framework pair (e.g., TS with Vitest, Python with pytest, Swift with XCTest, and Playwright for E2E)
- Step 2: Install and run the framework blocks shown in Quick Start by Framework and run tests (e.g., npx vitest, pytest, swift test, npx playwright test)
- Step 3: Review results, iterate with Red-Green-Refactor, and refine coverage
Best Practices
- Follow the language-specific framework guidance (Vitest/Jest for TS, pytest for Python, XCTest/XCUITest for Swift)
- Use the provided test patterns (Arrange-Act-Assert, async testing, and mocking) to structure tests
- Adopt the TDD Red-Green-Refactor cycle for new features
- Leverage coverage commands to measure test reach and identify gaps
- Isolate tests, minimize shared state, and use mocks to speed up and stabilize runs
Example Use Cases
- Unit test a TS Cart.totalWithTax using Vitest
- Python API test with pytest and httpx AsyncClient for /users
- Swift unit test with XCTest for a model method
- React component test using Testing Library in TS/Jest
- E2E Playwright test for a login flow