UNPKG

lightningimg

Version:

A blazing fast, transparent, and safe image converter powered by WebAssembly. Convert PNG, JPG, TIFF, and GIF images to optimized WebP format with high performance and cross-platform compatibility.

105 lines (84 loc) โ€ข 3.61 kB
# ๐Ÿงช LightningImg Testing Suite This document describes the comprehensive testing setup for the LightningImg WASM-only ESM implementation. ## ๐Ÿ“‹ Available Tests ### 1. **ESM Node.js Test** (`test:esm`) - **File**: `test-esm.js` - **Purpose**: Tests the WASM module in Node.js environment - **Features**: - Loads actual image files from `test_images/` - Tests all core functions: `getImageInfo`, `convertImageBuffer`, `isSupportedFormat` - Uses Node.js WASM target (`pkg-node/`) - Validates real-world image conversion scenarios ### 2. **Browser Puppeteer Test** (`test:browser`) - **File**: `test-browser-puppeteer.js` + `browser-test-simple.html` - **Purpose**: Automated browser testing using Puppeteer - **Features**: - Creates test images using Canvas API - Tests WASM module in real browser environment - Uses web WASM target (`pkg/`) - Validates browser-specific scenarios (CORS, ES modules, etc.) - Includes HTTP server for proper WASM loading - Takes screenshots for debugging - Comprehensive logging and error handling ### 3. **WASM Unit Tests** (`test:wasm`) - **Location**: `lightningimg-wasm/` directory - **Purpose**: Tests the underlying Rust WASM code - **Features**: Rust-level unit tests and WASM binding validation ## ๐Ÿš€ Running Tests ```bash # Run all tests (ESM + Browser) pnpm test # Run individual tests pnpm run test:esm # Node.js ESM test pnpm run test:browser # Puppeteer browser test pnpm run test:wasm # WASM unit tests # Run examples pnpm run example:simple # Simple Node.js example ``` ## ๐Ÿ“Š Test Results Summary ### Node.js Environment (ESM Test) - โœ… WASM module loading - โœ… Image info extraction - โœ… Format validation - โœ… Image conversion (PNG โ†’ WebP) - โœ… File I/O operations ### Browser Environment (Puppeteer Test) - โœ… WASM module loading via ES modules - โœ… Canvas API image generation - โœ… Dynamic imports working - โœ… All core functions operational - โœ… Excellent compression ratios (~71% for test images) - โœ… Cross-browser compatibility (via Chromium) ## ๐Ÿ”ง Technical Details ### Browser Test Architecture 1. **HTTP Server**: Custom server for proper MIME types and CORS headers 2. **Canvas Generation**: Creates test images dynamically in browser 3. **Puppeteer Integration**: Automated browser control and result collection 4. **Environment Detection**: Automatically loads correct WASM target ### Test Coverage - โœ… Module loading in both Node.js and browser - โœ… All exported functions (`convertImageBuffer` with resize support, `getImageInfo`, `isSupportedFormat`) - โœ… Error handling and edge cases - โœ… Performance metrics and compression ratios - โœ… Real-world image processing scenarios ## ๐Ÿ“ Test Files ``` test-esm.js # Node.js ESM test test-browser-puppeteer.js # Puppeteer browser test runner browser-test-simple.html # Browser test page browser-example.html # Interactive browser demo example-simple.js # Simple usage example test_images/ # Test image assets โ”œโ”€โ”€ defuss_logo_png.png โ”œโ”€โ”€ defuss_logo_jpg.jpg โ””โ”€โ”€ defuss_logo_tiff.tiff ``` ## ๐ŸŽฏ Success Criteria Both tests validate: - โœ… ESM module system compatibility - โœ… WASM loading and initialization - โœ… Cross-environment functionality (Node.js + Browser) - โœ… Image conversion accuracy - โœ… Performance and compression quality - โœ… Error handling and edge cases The testing suite ensures the LightningImg WASM-only implementation works reliably across all target environments with consistent API behavior.