Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions .cursorrules
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Riteway - Unit Testing Library

## Project Overview
Riteway is a JavaScript unit testing library that forces developers to write **R**eadable, **I**solated, **T**horough, and **E**xplicit tests. Built on top of tape, it provides a simple API that ensures every test answers the 5 essential questions:

1. What is the unit under test?
2. What should it do?
3. What was the actual output?
4. What was the expected output?
5. How do you reproduce the failure?

## Architecture & Key Components

### Core API
- `describe(unit, testFunction)` - Main test function
- `assert({given, should, actual, expected})` - Assertion function with required prose descriptions
- `Try(fn, ...args)` - Safe function execution with error handling
- `match(text)` - Text/pattern matching utility for component testing
- `render(component)` - React component rendering utility
- `countKeys(obj)` - Object key counting utility

### Module Structure
- `/source/` - Main source code (CommonJS)
- `/esm/` - ES module versions (copied from source)
- `/bin/riteway` - CLI test runner
- Type definitions in root (`.d.ts` files)

## Coding Standards & Patterns

### Test Writing Patterns
```javascript
describe('functionName()', async assert => {
assert({
given: 'a clear description of input/context',
should: 'describe expected behavior',
actual: functionCall(input),
expected: expectedOutput
});
});
```

### Error Handling
- Use `Try()` for testing functions that may throw
- Always handle async operations properly
- Prefer async/await over raw promises

### Code Style
- Use ES6+ features (arrow functions, destructuring, etc.)
- Prefer const over let when possible
- Use descriptive variable names
- Follow existing formatting patterns (2 spaces, semicolons)

### React Component Testing
```javascript
const $ = render(<Component prop="value" />);
const contains = match($('.selector').html());
assert({
given: 'component with props',
should: 'render expected content',
actual: contains('expected text'),
expected: 'expected text'
});
```

## Development Workflow

### Common Commands
- `npm test` - Run all tests
- `npm run lint` - Run ESLint
- `npm run typecheck` - TypeScript checking
- `npm run esm` - Update ESM modules
- `npm run watch` - Watch mode for development

### Build Process
1. Source files are in `/source/`
2. ESM versions are generated via copy to `/esm/`
3. TypeScript definitions are manually maintained
4. Babel is used for transpilation in tests

### Testing Guidelines
- Every test must have `given`, `should`, `actual`, `expected`
- Use prose descriptions that read like sentences
- Test one thing per assertion
- Prefer isolated unit tests
- Use `describe.only()` for focused testing
- Use `describe.skip()` to temporarily disable tests

## Dependencies & Tools
- **tape** - Underlying test runner
- **cheerio** - DOM manipulation for component testing
- **react/react-dom** - For component rendering
- **babel** - Transpilation
- **eslint** - Linting
- **typescript** - Type checking (dev only)

## File Naming Conventions
- `*-test.js` - Test files
- `*.d.ts` - TypeScript definitions
- Main modules: `riteway.js`, `match.js`, `render-component.js`, etc.

## Key Design Principles
1. **Explicitness over brevity** - Every test should be completely clear
2. **Readability first** - Tests should read like documentation
3. **Fail fast and clear** - Test failures should immediately show the problem
4. **Minimal API surface** - Keep the API small and focused
5. **TAP compatibility** - Output should work with TAP ecosystem tools

## Common Issues & Solutions
- Missing babel config causes syntax errors - ensure `.babelrc` is properly configured
- ESM modules need manual updating via `npm run esm`
- TypeScript checking is separate from runtime - run `npm run typecheck`
- For React testing, ensure proper imports and babel presets

## When Contributing
- Follow existing test patterns exactly
- Ensure all tests pass before submitting
- Run linting and type checking
- Update ESM modules if source changes
- Maintain TypeScript definitions for API changes
- Keep test output clear and readable
38 changes: 38 additions & 0 deletions AI_SETUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# AI Development Assistant Setup

This repository includes configuration files to help AI assistants (like GitHub Copilot, Cursor, and others) understand the Riteway testing library and provide better development assistance.

## Files Added

### `.cursorrules`
Project-wide configuration that provides AI assistants with:
- Complete project overview and architecture
- Coding standards and patterns used in Riteway
- Test writing conventions and best practices
- Development workflow and common commands
- Key design principles and guidelines

### `/ai` Directory
Collection of specialized prompts and documentation for common development scenarios:

- **`README.md`** - Overview of available AI prompts
- **`test-writing.md`** - Comprehensive patterns for writing Riteway tests
- **`component-testing.md`** - React component testing with Riteway utilities
- **`api-development.md`** - Guidelines for extending the Riteway API
- **`debugging.md`** - Common issues and debugging strategies
- **`refactoring.md`** - Safe refactoring patterns and techniques

## Benefits

These configurations help AI assistants:
- Understand Riteway's unique testing philosophy (Readable, Isolated, Thorough, Explicit)
- Generate proper test code following the required `{given, should, actual, expected}` pattern
- Suggest appropriate debugging approaches for common test failures
- Maintain code quality and consistency with project standards
- Provide relevant examples and patterns for specific development tasks

## Usage

The configuration automatically activates when using compatible AI tools in this repository. No additional setup is required - AI assistants will automatically reference these files to provide contextually appropriate suggestions and help.

For developers using Cursor, VS Code with Copilot, or other AI-enhanced editors, you should notice more accurate and helpful suggestions when working with Riteway code and tests.
15 changes: 15 additions & 0 deletions ai/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# AI Development Prompts for Riteway

This directory contains prompts and templates to help AI assistants understand and work with the Riteway testing library.

## Available Prompts

- `test-writing.md` - Templates and patterns for writing Riteway tests
- `component-testing.md` - React component testing patterns
- `api-development.md` - Guidelines for extending the Riteway API
- `debugging.md` - Common debugging scenarios and solutions
- `refactoring.md` - Patterns for safely refactoring code and tests

## Usage

These prompts are designed to provide context and examples for AI assistants when working on Riteway development tasks. Reference them when asking for help with specific development scenarios.
Loading