#!/usr/bin/env node import { optimizeImage } from 'wasm-image-optimization'; import { cropAndConvertToAvif, crawlAndProcessImage } from '../src/services/imageCrop.js'; async function run() { console.log('--- 1. Testing synthetic images ---'); // Synthetic test 1: White border const whiteSvg = ` `; const whiteImg = Buffer.from((await optimizeImage({ image: whiteSvg, format: 'png' })).data); const res1 = await cropAndConvertToAvif(whiteImg); console.log(`White border: 300x300 -> ${res1.width}x${res1.height}, ${res1.size} bytes`); if (res1.width !== 110 || res1.height !== 110) { throw new Error(`Expected 110x110, got ${res1.width}x${res1.height}`); } // Synthetic test 2: Transparent border const transSvg = ` `; const transImg = Buffer.from((await optimizeImage({ image: transSvg, format: 'png' })).data); const res2 = await cropAndConvertToAvif(transImg); console.log(`Transparent border: 300x300 -> ${res2.width}x${res2.height}, ${res2.size} bytes`); if (res2.width !== 130 || res2.height !== 90) { throw new Error(`Expected 130x90, got ${res2.width}x${res2.height}`); } // Synthetic test 3: Outer transparent, inner white border const mixedSvg = ` `; const mixedImg = Buffer.from((await optimizeImage({ image: mixedSvg, format: 'png' })).data); const res3 = await cropAndConvertToAvif(mixedImg); console.log(`Mixed border: 400x400 -> ${res3.width}x${res3.height}, ${res3.size} bytes`); if (res3.width !== 110 || res3.height !== 70) { throw new Error(`Expected 110x70, got ${res3.width}x${res3.height}`); } console.log('\nAll synthetic tests PASSED!'); // CLI URL test if provided as argument const testUrl = process.argv[2]; if (testUrl) { console.log(`\n--- 2. Crawling URL: ${testUrl} ---`); const urlRes = await crawlAndProcessImage(testUrl); console.log(`Crawled & processed: ${urlRes.width}x${urlRes.height}, ${urlRes.size} bytes`); } process.exit(0); } run().catch((err) => { console.error('Test failed:', err); process.exit(1); });