How to Contribute
This guide walks you through setting up the LiveDoc development environment, understanding the project structure, and submitting changes. By the end, you'll be ready to fix bugs, add features, or improve documentation.
Prerequisites
- Git
- Node.js 18+
- pnpm (
npm install -g pnpm)
Overview
LiveDoc is a pnpm monorepo. The core Vitest integration lives in
packages/vitest. Tests are written using LiveDoc itself (dogfooding). All
test files end in .Spec.ts.
Step 1: Clone and Install
git clone https://github.com/nicktho/livedoc.git
cd livedoc
pnpm install
Step 2: Build the Package
pnpm --filter @swedevtools/livedoc-vitest build
Step 3: Run Tests
# Run all specs
pnpm --filter @swedevtools/livedoc-vitest test
# Run a specific spec file
pnpm --filter @swedevtools/livedoc-vitest test -- --testPathPattern="Feature"
# Watch mode
pnpm --filter @swedevtools/livedoc-vitest test -- --watch
Step 4: Understand the Project Structure
packages/vitest/
├── _src/
│ ├── app/ # Core implementation
│ │ ├── livedoc.ts # DSL functions (feature, scenario, etc.)
│ │ ├── parser/ # Title and data parsing
│ │ ├── model/ # Data structures (Feature, Scenario, Step)
│ │ └── reporter/ # Output formatters
│ └── test/ # Specs for the package itself
├── docs/ # Source documentation
├── dist/ # Build output
└── package.json
Key files:
| File | Purpose |
|---|---|
_src/app/livedoc.ts | DSL functions (feature, scenario, given, etc.) |
_src/app/index.ts | Public exports |
_src/app/setup.ts | Global registration for globals mode |
_src/app/globals.d.ts | TypeScript declarations for globals |
_src/app/model/ | Data model classes |
_src/app/reporter/ | Reporter implementations |
Step 5: Make Your Changes
- Create a feature branch:
git checkout -b feature/my-feature - Make your changes in
_src/app/ - Add or update tests in
_src/test/ - Run tests:
pnpm --filter @swedevtools/livedoc-vitest test - Build:
pnpm --filter @swedevtools/livedoc-vitest build
Complete Example: Adding a DSL Feature
If adding a new keyword or modifying DSL behavior:
- Update
livedoc.ts— add or modify the function - Update
index.ts— export it - Update
setup.ts— register onglobalThis(if applicable) - Update
globals.d.ts— add the TypeScript declaration - Add tests — cover happy path and edge cases
- Update docs — document the new feature
Example test (LiveDoc specs use LiveDoc):
// _src/test/MyFeature.Spec.ts
import { feature, scenario, given, when, Then as then } from '../app/livedoc';
feature(`My New Feature
@core
Tests for the newly added DSL keyword.
`, () => {
scenario("Basic usage works correctly", () => {
given("a spec using the new keyword", () => {
// setup
});
when("the spec is executed", () => {
// action
});
then("the expected behavior occurs", () => {
// assertion
expect(true).toBe(true);
});
});
});
Common Variations
Writing Tests — Key Guidelines
-
Embed test data in step titles (LiveDoc's core practice):
// ✅ Good — self-documenting
given("a user with '$100' balance", (ctx) => {
const balance = ctx.step.values[0];
});
// ❌ Avoid — hidden values
given("a user with balance", () => {
const balance = 100;
}); -
One concept per scenario — keep scenarios focused
-
Descriptive scenario names — describe the behavior, not the test
Code Style
- TypeScript strict mode — no
anyunless absolutely necessary - Meaningful names —
createStepFunctionnotcsf - Comments for "why" — code shows "what", comments explain "why"
Running the Viewer During Development
# Start the viewer for visual testing
./scripts/start-viewer.ps1 -KillStale
# Start the LiveDoc server
./scripts/start-livedoc-server.ps1 -KillStale
Submitting a Pull Request
- Ensure tests pass:
pnpm --filter @swedevtools/livedoc-vitest test - Ensure build succeeds:
pnpm --filter @swedevtools/livedoc-vitest build - Push your branch and open a PR with:
- Clear description of what changed and why
- Link to any related issues
- Screenshots if UI-related
PR Checklist
- Tests added or updated
- Documentation updated (if applicable)
- Build passes
- No new TypeScript errors
- Test data embedded in step titles (self-documenting)
Reporting Bugs
Open an issue with:
- What you expected to happen
- What happened instead
- Steps to reproduce
- Your environment (Node version, OS, Vitest version)
- Minimal reproduction (if possible)
Feature Requests
Open an issue with:
- The problem you're trying to solve
- Your proposed solution
- Alternatives you considered
Troubleshooting
| Problem | Cause | Solution |
|---|---|---|
pnpm install fails | Wrong pnpm version | Install latest pnpm: npm install -g pnpm |
| Build errors | Missing dependencies | Run pnpm install from the repo root |
| Tests fail after changes | Regression in DSL code | Check the specific failure — compare with the Mocha reference in _archive/livedoc-mocha |
| Import errors in tests | Wrong import path | Tests import from ../app/livedoc, not from the package name |
| Viewer not connecting | Server not running | Use ./scripts/start-viewer.ps1 -KillStale |
Related
- Setup: Explicit Imports — how end-users configure the package
- Custom Reporters — extending the reporter system
- Best Practices — writing quality specs
- Migration from Mocha — understanding the legacy codebase