Add automated tests for CLI commands
Description
The Fedify CLI currently has no automated tests (0% test coverage), while the main library has comprehensive test coverage. This makes it difficult to ensure CLI commands work correctly and prevents regression testing when making changes.
Current State
- CLI directory (
cli/) has no unit tests or integration tests - Main library has extensive test coverage using Deno's test framework
- CLI commands are only manually tested
- No CI/CD validation for CLI functionality
cli/deno.jsonhas no test task defined
Proposed Solution
Add comprehensive test coverage for CLI commands using Deno.test() directly, including:
-
Unit tests for individual CLI modules:
lookup.ts- Test command parsing, option validation, error handlinginbox.tsx- Test server setup, request handlingnode.ts- Test NodeInfo command functionalitytunnel.ts- Test tunnel creation logicinit.ts- Test project initialization- Helper modules (
docloader.ts,utils.ts,cache.ts, etc.)
-
Integration tests for CLI commands:
- Test actual command execution with various options
- Test error scenarios and edge cases
- Test CLI output formatting and messaging
-
Test infrastructure:
- Add test task to
cli/deno.json - Set up test utilities and mocks
- Add test coverage reporting
- Add test task to
Implementation Approach
Phase 1: Test Infrastructure Setup
- [ ] Add
testtask tocli/deno.json - [ ] Create test utilities and helper functions
- [ ] Set up mocking for external dependencies (HTTP requests, file system, etc.)
Phase 2: Unit Tests
- [ ]
utils.test.ts- Test utility functions - [ ]
cache.test.ts- Test cache operations - [ ]
docloader.test.ts- Test document loader configurations - [ ]
table.test.ts- Test table formatting utilities
Phase 3: Command Tests
- [ ]
lookup.test.ts- Test lookup command logic - [ ]
inbox.test.ts- Test inbox command functionality - [ ]
node.test.ts- Test node command - [ ]
tunnel.test.ts- Test tunnel command - [ ]
init.test.ts- Test init command
Phase 4: Integration Tests
- [ ] End-to-end CLI command execution tests
- [ ] CLI option parsing and validation tests
- [ ] Error message and help text tests
Example Test Structure
Using Deno's built-in testing framework:
// cli/lookup.test.ts
import { assertEquals, assertRejects } from "@std/assert";
import { command as lookupCommand } from "./lookup.ts";
Deno.test("lookup command - should validate URLs", async () => {
// Test URL validation logic
});
Deno.test("lookup command - should handle timeout options", async () => {
// Test timeout option parsing
});
Deno.test("lookup command - should format output correctly", async () => {
// Test output formatting
});
Testing Challenges & Considerations
- External Dependencies: Mock HTTP requests, file system operations, tunnel services
- CLI Interaction: Test command-line argument parsing and validation
- Async Operations: Handle async operations like network requests and server startup
- Output Testing: Validate console output, colors, and formatting
- Environment Isolation: Ensure tests don't interfere with each other
Benefits
- Regression Prevention: Catch breaking changes before they reach users
- Documentation: Tests serve as examples of how CLI commands should work
- Confidence: Make changes to CLI code with confidence
- Code Quality: Improve code structure through testability requirements
- Contributor Onboarding: Help new contributors understand CLI functionality
Getting Started
This is an excellent issue for new contributors because:
- Testing provides a great way to understand the codebase
- You can start with simple utility function tests
- Each CLI command can be tested independently
- No complex domain knowledge required initially
- Clear success criteria (tests pass/fail)
Acceptance Criteria
- [ ] All CLI modules have unit tests with good coverage
- [ ] Integration tests cover main CLI workflows
- [ ] Test task added to
cli/deno.json(e.g.,"test": "deno test **/*.test.ts") - [ ] Tests run successfully in CI/CD pipeline
- [ ] Test coverage reporting is available
- [ ] Documentation includes testing guidelines for future CLI features
Suggested First Steps
- Start by adding a test task to
cli/deno.json - Create tests for utility functions in
utils.ts - Add tests for simple modules like
cache.ts - Gradually work up to testing CLI commands themselves
Contributors can work on different test files in parallel, making this a great collaborative issue.
I will add test task for fedify node first.
I'll work on fedify tunnel