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.

65 lines (56 loc) 2.24 kB
/** * Test script for LightningImg ESM WASM-only implementation */ import { readFileSync } from "node:fs"; import { convertImageBuffer, getImageInfo } from "./index.js"; async function testESMWasmOnly() { console.log("🚀 Testing LightningImg ESM WASM-only implementation...\n"); try { // Test with a sample image if available const testImagePath = "./test_images/IMG_3236.jpg"; try { const imageBuffer = readFileSync(testImagePath); console.log(`📷 Testing with image: ${testImagePath}`); console.log(`Original size: ${imageBuffer.length} bytes`); // Test getImageInfo console.log("🔍 Testing getImageInfo..."); try { const imageInfo = await getImageInfo(imageBuffer); console.log("Image info:", imageInfo); console.log("✅ getImageInfo works!\n"); // Test convertImageBuffer console.log("🔄 Testing convertImageBuffer (JPG to WebP)..."); const convertedBuffer = await convertImageBuffer(imageBuffer); console.log(`Converted size: ${convertedBuffer.length} bytes`); console.log( `Compression ratio: ${((1 - convertedBuffer.length / imageBuffer.length) * 100).toFixed(1)}%`, ); console.log("✅ convertImageBuffer works!\n"); // Test resize functionality console.log("📏 Testing resize functionality..."); const resizedBuffer = await convertImageBuffer(imageBuffer, 150, 200); const resizedInfo = await getImageInfo(resizedBuffer); console.log(`Resized to: ${resizedInfo.width}×${resizedInfo.height}`); console.log(`Resized size: ${resizedBuffer.length} bytes`); console.log("✅ Resize functionality works!\n"); console.log( "🎉 All tests passed! ESM WASM-only implementation is working correctly.", ); } catch (wasmError) { console.error("❌ WASM function error:", wasmError.message); throw wasmError; } } catch (imageError) { console.log( "⚠️ No test image found, but core functions work. Image tests skipped.", ); console.log("🎉 Core ESM WASM implementation is working correctly."); } } catch (error) { console.error("❌ Test failed:", error.message); console.error(error.stack); process.exit(1); } } // Run tests testESMWasmOnly().catch(console.error);