Skip to content

Instantly share code, notes, and snippets.

@shashank-shekhar
Created January 7, 2026 04:25
Show Gist options
  • Select an option

  • Save shashank-shekhar/c830311d4459838234135cda6f5704ae to your computer and use it in GitHub Desktop.

Select an option

Save shashank-shekhar/c830311d4459838234135cda6f5704ae to your computer and use it in GitHub Desktop.
Claude Code custom command to document all the tests in a project
description tools
Document all tests in this project. Keep the lists up-to-date.
Bash, Glob, Grep, Read, Write, Edit

Document tests efficiently using framework discovery and incremental updates. Handles multi-language projects.

Primary Goal

First check if the project's claude.md (or CLAUDE.md) file contains testing framework information. If not, detect frameworks and update the file with:

  • Testing frameworks used
  • Commands to list all tests
  • Test file patterns

Strategy

  1. Check Project Documentation: Look for claude.md or CLAUDE.md in project root
  2. Verify Testing Info: Check if testing frameworks and commands are documented
  3. Detect if Missing: If absent, detect frameworks by directory
  4. Update claude.md: Add testing section with frameworks and commands
  5. Document Tests: Proceed with test documentation using detected frameworks

Checking for Existing Testing Info

When reading the project's claude.md, look for a section about testing (headers like "Testing", "Tests", "Test Frameworks", etc.). Complete testing information should include:

  • Framework names (e.g., Jest, xUnit, pytest)
  • Test file patterns or locations
  • Commands to list or run tests

If any of these are missing, the testing section is incomplete and should be updated.

Updating claude.md

If the project's claude.md (or CLAUDE.md) is missing testing information, add or update a section like:

## Testing

### Frameworks
- **Frontend**: Jest (JavaScript/TypeScript)
  - Test pattern: `**/*.test.{js,jsx,ts,tsx}`
  - List tests: `npm test -- --listTests`

- **Backend**: xUnit (.NET)
  - Test pattern: `**/*Tests.csproj`
  - List tests: `dotnet test --list-tests`

- **API**: pytest (Python)
  - Test pattern: `**/test_*.py`, `**/*_test.py`
  - List tests: `pytest --collect-only -q`

### Commands
- Run all tests: `npm run test:all` or framework-specific commands
- Run specific suite: See framework commands above

Adjust the format based on detected frameworks and project structure.

Framework Detection (Per Directory)

  • .NET: Look for *.csproj, *.sln → Use dotnet test --list-tests

    • Test runners: xUnit, NUnit, MSTest (detect from package references)
    • Test patterns: **/*Tests.csproj, **/*.Test.csproj, **/Tests/**/*.cs
  • JavaScript/TypeScript: Look for package.json → Check for jest/vitest/mocha/jasmine

    • Jest: npm test -- --listTests or npx jest --listTests
    • Vitest: npx vitest list or glob for test files
    • Mocha: Check scripts in package.json
    • Test patterns: **/*.test.*, **/*.spec.*, **/__tests__/**/*
  • Python: Look for pyproject.toml, pytest.ini, setup.cfg → Use pytest --collect-only

    • unittest: python -m unittest discover
    • Test patterns: **/test_*.py, **/*_test.py, **/tests/**/*.py
  • Go: Look for go.mod → Use go test -list .

    • Test patterns: **/*_test.go
  • Rust: Look for Cargo.toml → Use cargo test -- --list

    • Test patterns: **/tests/**/*.rs, files with #[test] or #[cfg(test)]
  • Ruby: Look for Gemfile → Check for rspec/minitest

    • RSpec: bundle exec rspec --dry-run
    • Test patterns: **/spec/**/*_spec.rb, **/test/**/*_test.rb
  • Java: Look for pom.xml or build.gradle → Check for JUnit/TestNG

    • Maven: mvn test -DdryRun=true
    • Gradle: gradle test --dry-run
    • Test patterns: **/src/test/**/*Test.java

Cache Format

Store in .test-docs-cache.json at project root:

{
  "lastRun": "2025-12-22T10:30:00Z",
  "directories": {
    "frontend/": {
      "framework": "vitest",
      "testPattern": "**/*.test.ts"
    },
    "backend/": {
      "framework": "dotnet",
      "testRunner": "xunit"
    },
    "api/": {
      "framework": "dotnet",
      "testRunner": "nunit"
    }
  },
  "files": {
    "frontend/src/App.test.tsx": {
      "mtime": 1703251200,
      "hash": "abc123",
      "directory": "frontend/"
    },
    "backend/Tests/UnitTest1.cs": {
      "mtime": 1703251200,
      "hash": "def456",
      "directory": "backend/"
    }
  }
}

Directory Detection Logic:

  • Each test file belongs to a directory (find nearest parent with framework markers)
  • Cache stores framework per directory
  • On subsequent runs, use cached framework info for that directory

Workflow

  1. Check for claude.md - Look for claude.md or CLAUDE.md in project root
  2. Parse existing testing info - Check if Testing section exists with frameworks and commands
  3. If testing info is missing or incomplete:
    • Detect frameworks using the detection logic below
    • Generate testing section with frameworks, patterns, and commands
    • Update or create claude.md with the testing section
  4. Load cache - Read .test-docs-cache.json (if documenting tests)
  5. Find test files - Use git or glob to find test files
  6. Group by directory - Organize files by their parent directory
  7. For each directory:
    • Use framework info from claude.md if available
    • Otherwise, use cached framework or detect it
    • Store detection result in cache
  8. Filter to changed files only - Compare mtimes from cache
  9. Process changed files using appropriate framework commands
  10. Update docs/tests.md - Merge with existing content
  11. Save cache with updated directory frameworks and file metadata

.NET Commands

  • List tests: dotnet test --list-tests --no-build or dotnet test -t
  • Find test projects: Glob for **/*Tests.csproj, **/*.Test.csproj
  • Detect runner: Parse .csproj for PackageReference (xunit, nunit, mstest)
  • Common attributes: [Fact], [Theory], [Test], [TestMethod]

JavaScript Commands

  • Jest: jest --listTests or npm test -- --listTests
  • Vitest: vitest list or glob for test files
  • Common patterns: **/*.test.*, **/*.spec.*, **/__tests__/**/*

Output Format

CRITICAL: All tests MUST be documented in tables. NEVER use bullet lists for test documentation.

Add or append to docs/tests.md in markdown format. Each test type section MUST contain a table.

Required table columns for ALL test groups:

  • File Path
  • Test Name (class/function + method)
  • Description (what is being tested)

Grouping

Group tests by type using section headers, with each section containing a table:

Unit Tests

File Path Test Name Description
... ... ...

Integration Tests

File Path Test Name Description
... ... ...

Available test type sections (only include those that exist in the project):

  • Unit Tests - Isolated tests for individual functions/classes
  • Integration Tests - Tests for component interactions
  • E2E Tests - End-to-end user flow tests
  • Snapshot Tests - UI/output snapshot comparisons
  • Contract Tests - API contract verification
  • Performance Tests - Load/stress/benchmark tests

IMPORTANT: Every test group MUST use the table format shown above. Do NOT create bullet lists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment