UNPKG

js-partial-classes

Version:

A utility package for supplementing main classes with methods from partial classes, supporting both static and instance methods.

113 lines (87 loc) 3.31 kB
# Test Suite Documentation This directory contains comprehensive tests for the `js-partial-classes` library. ## Test Structure ### Test Files 1. **`basic.test.js`** - Basic functionality tests - Tests static initialization with supplement - Tests iterateDescriptors function - Simple integration tests 2. **`supplement.test.js`** - Comprehensive supplement function tests - Direct class reference supplementation - String path import supplementation - Promise import supplementation - Method override behavior - Constructor exclusion - Non-writable properties handling 3. **`supplementAll.test.js`** - Directory-based supplementation tests - JavaScript file (.js) support - TypeScript file (.ts) support - ES Module file (.mjs) support - CommonJS file (.cjs) support - Mixed file types - Non-supported files - Empty directory handling - Invalid directory handling 4. **`iterateDescriptors.test.js`** - Utility function tests - Static methods iteration - Instance methods iteration - Constructor exclusion - Empty class handling - Properties vs methods - Non-writable properties - Callback functionality - Descriptor structure - Error handling 5. **`run-all-tests.js`** - Main test runner - Executes all test suites - Provides comprehensive summary - Reports success/failure statistics ### Test Utilities - **`test-partial.js`** - Test partial class used by basic tests ## Running Tests ### All Tests ```bash npm test ``` ### Individual Test Suites ```bash npm run test:basic npm run test:supplement npm run test:supplementAll npm run test:iterateDescriptors ``` ## Test Results Summary Based on the latest test run: ### ✅ Working Features - Basic supplement functionality with direct class references - Static and instance method supplementation - Constructor exclusion - Error handling for null/undefined inputs - Descriptor structure validation ### ⚠️ Issues Found 1. **Static Initialization**: The static initialization block in classes doesn't work as expected in the test environment 2. **Path Resolution**: Dynamic imports with relative paths need better handling 3. **Descriptor Filtering**: The iterateDescriptors function needs refinement for better property filtering ### 🔧 Fixes Applied 1. **Import Issues**: Fixed missing iterateDescriptors function definition 2. **Async Handling**: Added proper await for supplement calls in supplementAll 3. **Path Resolution**: Improved relative path handling for dynamic imports ## Test Coverage The test suite covers: -**Functionality**: All main functions (supplement, supplementAll, iterateDescriptors) -**File Extensions**: .js, .ts, .mjs, .cjs support -**Module Systems**: ES modules, CommonJS, TypeScript -**Error Handling**: Invalid inputs, missing files, etc. -**Edge Cases**: Empty classes, non-writable properties, etc. ## Continuous Integration The test suite is designed to be run in CI/CD environments and provides: - Clear pass/fail indicators - Detailed error messages - Comprehensive test summaries - Exit codes for automation ## Contributing When adding new features, please: 1. Add corresponding tests 2. Update this documentation 3. Ensure all tests pass 4. Follow the existing test patterns