import { describe, it, expect, beforeAll, afterAll } from 'vitest'; import fs from 'node:fs/promises'; import path from 'node:path'; import os from 'node:os'; import { registerImageConverters } from '../../src/converters/image.js'; import { resolve, listTargetFormats } from '../../src/converters/registry.js'; import { detectInputMime } from '../../src/mime.js'; let tmpDir; beforeAll(async () => { registerImageConverters(); tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'converter-image-')); }); afterAll(async () => { await fs.rm(tmpDir, { recursive: true, force: true }); }); describe('image converters', () => { it('registers every pair among the supported formats', () => { const targets = listTargetFormats('png').sort(); expect(targets).toEqual(['avif', 'gif', 'jpeg', 'jpg', 'tiff', 'webp']); }); it('converts a PNG fixture to WebP', async () => { const inputPath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.png'); const outputPath = path.join(tmpDir, 'output.webp'); const entry = resolve('png', 'webp'); await entry.convert(inputPath, outputPath); const detected = await detectInputMime(outputPath); expect(detected.mime).toBe('image/webp'); }); it('converts a PNG fixture to JPG', async () => { const inputPath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.png'); const outputPath = path.join(tmpDir, 'output.jpg'); const entry = resolve('png', 'jpg'); await entry.convert(inputPath, outputPath); const detected = await detectInputMime(outputPath); expect(detected.mime).toBe('image/jpeg'); }); });