Comprehensive testing strategy for jargons.dev ensuring code quality and reliability across all components.
- vitest - Modern testing framework with TypeScript support
- happy-dom - Browser environment simulation for testing
- @testing-library/jest-dom - DOM testing utilities and assertions
- @vitest/coverage-v8 - Code coverage reporting
- 161 tests across 7 test suites
- 99.4% overall test success rate (160 passing, 1 unrelated failure)
- 98.5% coverage on constants validation (
constants.js) - 95.34% coverage on crypto functions (
src/lib/utils/crypto.js) - 100% coverage on utility functions (
src/lib/utils/index.js) - Complete coverage on business logic functions (
submit-word.js,word-editor.js,branch.js,fork.js)
npm run test # Run all tests
npm run test:watch # Run tests in watch mode
npm run test:ui # Open Vitest UI interface
npm run test:coverage # Generate detailed coverage reporttests/
├── setup.js # Test environment configuration with MSW
├── fixtures/ # Test data and API response mocks
│ ├── test-data/
│ │ └── index.js # Sample words and repository details
│ └── github-responses/
│ └── index.js # GitHub API response fixtures
├── mocks/
│ └── github-api.js # MSW handlers for GitHub API endpoints
└── unit/
├── constants/
│ └── constants.test.js # Project constants validation
├── lib/ # Business logic tests
│ ├── submit-word.test.js # PR creation and submission logic
│ ├── word-editor.test.js # Word file management operations
│ ├── branch.test.js # Git branch operations
│ └── fork.test.js # Repository forking logic
└── utils/
├── crypto.test.js # Encryption/decryption functions
└── index.test.js # Utility functions
- Utility Functions - Date calculations, string parsing, URL building, text formatting
- Crypto Functions - Encryption/decryption with security validation and error handling
- Constants Validation - Project configuration, labels, and SEO compliance
- Word management functions (
submit-word.js,word-editor.js) - Git operations (
branch.js,fork.js) - GitHub API interactions and error handling
- MSW (Mock Service Worker) integration for realistic API testing
- Phase 3: Component Tests (React components, Astro layouts)
- Phase 4: Integration Tests (API endpoints, data flow)
- Phase 5: End-to-End Tests (User workflows, browser testing)
- 39 test cases covering all 10 utility functions
- 100% coverage with comprehensive edge case testing
- Functions tested: date calculations, string parsing, URL building, text formatting
- 17 test cases with security-focused validation
- 95.34% coverage including round-trip validation and error handling
- Tests: encryption format validation, tampered data detection, edge cases
- 20 test cases ensuring proper structure and values
- 98.5% coverage with configuration validation
- Tests: PROJECT_REPO_DETAILS validation, LABELS consistency, SEO compliance
- 19 test cases covering PR creation and submission workflow
- 100% coverage of pull request title generation, template rendering, and label assignment
- Tests: PR title formatting, template substitution, repository parsing, GitHub API error handling
- 26 test cases covering word file management operations
- 100% coverage of word creation, updates, and retrieval
- Tests: base64 encoding, template processing, path normalization, special character handling
- 24 test cases covering Git branch management
- 100% coverage of branch creation, retrieval, and deletion
- Tests: branch reference formatting, repository parsing, complex ref handling, error propagation
- 16 test cases covering repository forking logic
- 100% coverage of fork detection, creation, and synchronization
- Tests: GraphQL queries, fork status checking, automatic updates, nested error handling
- Unit tests:
*.test.js - Integration tests:
*.integration.test.js - E2E tests:
*.e2e.test.js
import { describe, it, expect } from "vitest";
import { functionName } from "../src/lib/utils";
describe("Function Group", () => {
it("should handle basic case", () => {
expect(functionName("input")).toBe("expected");
});
it("should handle edge cases", () => {
expect(functionName("")).toBe("");
expect(functionName(null)).toThrow();
});
});The test environment is configured in tests/setup.js with:
- Environment variable mocking for crypto keys
- GitHub configuration mocking
- DOM testing utilities setup
- MSW (Mock Service Worker) for GitHub API mocking
- Comprehensive test fixtures for GitHub API responses
# Run specific test file
npm test -- tests/unit/utils/index.test.js
# Run business logic tests
npm test -- tests/unit/lib/
# Run specific business logic function tests
npm test -- tests/unit/lib/submit-word.test.js
# Run tests matching pattern
npm test -- --grep "crypto"
# Run with coverage for specific files
npm run test:coverage -- --include="**/utils/**"
# Run tests in UI mode
npm run test:uiGenerate detailed coverage reports with:
npm run test:coverageCoverage reports include:
- Line coverage percentages
- Branch coverage analysis
- Function coverage metrics
- Uncovered line identification
- Follow existing patterns - Use established test structure and naming
- Aim for high coverage - Target >90% coverage on new code
- Include edge cases - Test error scenarios and boundary conditions
- Use descriptive names - Test names should clearly describe what's being tested
- Group related tests - Use
describeblocks to organize test suites
- Test behavior, not implementation - Focus on what the function does
- Keep tests isolated - Each test should be independent
- Use meaningful assertions - Prefer specific expectations over generic ones
- Mock external dependencies - Isolate code under test from external systems
- Use MSW for API testing - Mock GitHub API endpoints for realistic testing scenarios
- Test error scenarios - Verify proper error handling and propagation chains
Track testing progress in our GitHub issues:
- #171: Phase 1 - Foundation Tests ✅
- #172: Phase 2 - Business Logic Tests ✅
- #173: Phase 3 - Component Tests
- #174: Phase 4 - Integration Tests
- #175: Phase 5 - E2E Tests
- Test environment setup (happy-dom)
- Coverage configuration
- Test file patterns and exclusions
- Environment variable mocking
- Test utilities initialization
- Global test configuration
- MSW server setup for API mocking
- Test data fixtures - Sample words, repository details, and configuration
- GitHub API responses - Realistic API response mocks for testing
- MSW handlers - GitHub API endpoint mocking for comprehensive testing
- Phase 3 Implementation - Begin component testing for React/Astro components
- Enhanced API Testing - Expand MSW coverage for additional GitHub API endpoints
- Component Testing Framework - Set up React/Astro component testing infrastructure
- CI/CD Integration - Add automated testing to deployment pipeline
- Performance Testing - Add benchmarks for critical business logic functions