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
Markdown
# ๐งช 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.