This document outlines the testing approach for the Optional Rule Games Next.js blog to ensure basic functionality and catch breaks during upgrades and updates.
The testing strategy focuses on critical functionality that could break during dependency updates, Next.js upgrades, or content changes. It uses a three-tier approach to provide comprehensive coverage while remaining lightweight and maintainable.
Purpose: Test individual functions and utilities
Location: src/**/*.test.ts
Config: vitest.unit.config.ts
Environment: happy-dom for React components, node for utilities
Core Areas Covered:
-
Date utilities (
src/lib/utils.test.ts):- Date parsing and formatting
- URL generation with proper date formatting
- UTC handling to prevent timezone issues
-
String utilities:
- Text processing and normalization
- Slug generation and conversion
- Heading ID generation
-
Content management (
src/lib/content.test.ts):- Draft detection logic
- File filtering (production vs development)
- MDX file processing
-
Search functionality (
src/lib/search.test.ts):- Search index loading and validation
- Query processing and filtering
- Result ranking and limiting
-
Component logic (
src/components/Pagination.test.ts):- Pagination calculations
- Page range generation
-
React components (
src/components/__tests__/*.test.tsx):- SearchInput: Debouncing, keyboard shortcuts, URL handling
- User interactions and state management
- Props validation and rendering
Purpose: Ensure build process and static generation work correctly
Location: src/__tests__/build.test.ts
Coverage:
- Configuration file presence and validity
- Required directory structure
- Content file validation
- Build artifact verification
- Search index generation
Purpose: Test workflows and cross-system interactions
Location: src/__tests__/integration.test.ts
Coverage:
- Content processing to search pipeline
- URL generation consistency
- Pagination integration
- Draft filtering across operations
Purpose: Validate static site generation requirements
Location: src/__tests__/ssg.test.ts
Coverage:
- Dynamic route generation
- Trailing slash enforcement
- Image path normalization
- Build-time content processing
Purpose: Ensure WCAG compliance and screen reader support
Location: src/__tests__/accessibility.test.tsx
Coverage:
- ARIA attributes and roles
- Keyboard navigation
- Color contrast (semantic verification)
- Screen reader compatibility
# Run all unit tests
npm run test
# Run tests in watch mode during development
npm run test:watch
# Run tests with UI (browser-based)
npm run test:ui
# Run tests with coverage reporting
npm run test:coverage
# Run integration tests
npm run test:integration
# Run SSG-specific tests
npm run test:ssg
# Run accessibility tests
npm run test:a11y
# Run build verification (includes build + static tests)
npm run test:build
# Run just the static verification
npm run test:static
# Run all tests (unit + a11y + build)
npm run test:all- Why Critical: URL generation depends on correct date parsing
- Tests: UTC date parsing, URL path generation, timezone consistency
- Prevents: Broken post URLs after timezone/date library changes
- Why Critical: Core functionality for blog content management
- Tests: Draft filtering, MDX parsing, metadata extraction
- Prevents: Draft posts appearing in production, missing content
- Why Critical: Primary user interaction feature
- Tests: Index loading, query processing, result validation
- Prevents: Search breaking after Fuse.js or API changes
- Why Critical: Static site generation must work for deployment
- Tests: Configuration validation, artifact generation, file structure
- Prevents: Failed deployments, missing static files
When updating dependencies or Next.js:
- Run existing tests:
npm run test - Test build process:
npm run test:build - Manual verification:
- Start dev server:
npm run dev - Verify search functionality
- Check post navigation
- Validate draft filtering
- Start dev server:
Tests use mocked data and file system operations to ensure:
- Deterministic results: Tests don't depend on actual content files
- Fast execution: No real file I/O during testing
- Isolation: Tests don't affect real content or build artifacts
- New utility functions: Add tests to respective
.test.tsfiles - New components: Add component tests using Testing Library and Vitest
- New content features: Extend
content.test.tscoverage
- Keep tests focused on behavior, not implementation
- Use descriptive test names that explain the scenario
- Mock external dependencies (file system, network calls)
- Test both success and error conditions
- Unit tests should run in under 5 seconds
- Build tests can take longer but should complete under 30 seconds
- Use
vi.mock()to avoid slow operations
The testing strategy is designed to work in CI environments:
- No external dependencies required
- Deterministic test results
- Clear failure messages
- Separate test categories for different CI stages
- Utility functions: 90%+ coverage
- Content processing: 80%+ coverage
- Search functionality: 85%+ coverage
- Build verification: Critical paths covered
- Interactive experiences: Treat the Asteroids bundle as an embedded app. Exclude
src/app/(interactive)/**andsrc/features/games/**from the main coverage run so the core editorial stack is measured without the game engine skewing the report. - Dedicated suite later: Keep the option open to add a second Vitest config (for example
vitest.games.config.ts) that targets the excluded files with thresholds that match their complexity and browser needs. - Route integration focus: Replace the removed E2E smoke checks with focused component or static-render tests that exercise
generateStaticParams, pagination wiring, and fallback states using fixtures. This keeps confidence high without reintroducing brittle page-load tests. - Navigation guarantees: Expand RTL coverage for
Header,Footer,SmartLink,MarkdownLink, andMediaEmbedso link integrity, analytics guards, and content sanitisation are locked in.
- Update
vitest.unit.config.tsto exclude the interactive game paths and rerunnpm run test:coverageto confirm the core stack sits near the 45-48% mark. - IMPLEMENTED - Add targeted RTL suites for the navigation and content primitives listed above, asserting trailing slashes, GA opt-in/out, and external link handling. - IMPLEMENTED
- Introduce lightweight integration tests for representative paginated/tag routes that render the exported components with fixture content and validate metadata helpers. - IMPLEMENTED
- Re-assess the global thresholds once the new tests land; bump toward 55% if coverage rises accordingly, otherwise keep 50% and document the remaining gaps. - IMPLEMENTED at 60% Revisit in the future
- Spin up the optional
vitest.games.config.ts(or a Playwright test suite) when you are ready to harden the interactive bundle without impacting the primary CI gate.
As the project grows, consider adding:
- End-to-end tests with Playwright
- Visual regression testing
- Performance benchmarking
- Accessibility testing automation
- RSS feed validation
- Image optimization verification
This testing strategy provides a solid foundation for catching breaking changes while remaining maintainable and focused on the most critical functionality.