@critters/next v2.0.0
Critters Next.js Test Suite
This directory contains automated tests for the @critters/next package. The test suite is built using Jest and provides coverage for the main functionality of the library.
Test Coverage Overview
The following components of the library are covered by tests:
Utility Functions (
utils.test.ts)- String sanitization and formatting
- Error handling
- Environment detection
- Cryptographic signatures
Configuration (
config.test.ts)- Configuration initialization
- Singleton pattern validation
- Configuration getters and setters
- Feature flag management
Error Reporter (
reporter.test.ts)- Error report creation and submission
- Error handling for API communication
- Hook integration (before/after reporting)
- Disabled state handling
React Components (
components.test.ts)- Error boundary functionality
- Component wrapper behavior
- Error reporting integration
- Fallback UI rendering
Running the Tests
To run the tests, use the following command:
npm testFor watch mode during development:
npm run test:watchTo view coverage report:
npm run test:coverageTest Structure
Each test file focuses on testing a specific module:
__tests__/utils.test.ts: Tests for utility functions__tests__/config.test.ts: Tests for the configuration system__tests__/reporter.test.ts: Tests for the error reporting functionality__tests__/components.test.tsx: Tests for React components
Known Issues and Future Improvements
Some tests are currently failing due to mocking issues that need to be addressed:
- Server-side crypto detection
- React component state handling
- API response mocking
Coverage improvements needed for:
- Middleware functionality
- Collector modules
- Index exports
The coverage thresholds are temporarily set low (10%) to allow for progressive implementation. The target coverage should be:
- Statements: 80%
- Branches: 70%
- Functions: 80%
- Lines: 80%
Contributing to Tests
When adding new tests, follow these guidelines:
- Create test cases that isolate functionality as much as possible
- Use proper mocking to avoid dependencies on external services
- Follow the existing test structure and naming conventions
- Ensure test descriptions clearly explain what is being tested
- Address edge cases and error scenarios
Mock Structure
The test suite uses Jest's mocking capabilities:
- Module mocks in individual test files
- Global mocks in the
setup.jsfile - Environment simulation for browser/server contexts
To enhance mock coverage, update the mock implementations in the respective test files or add new globals to the setup.js file.