Regenerates the sample.png test fixture via sharp itself: the hand-encoded base64 PNG from the plan had valid magic bytes (enough to fool file-type's signature check) but was malformed past the header, which libpng rejected as soon as sharp actually tried to decode it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
48 lines
1.6 KiB
JavaScript
48 lines
1.6 KiB
JavaScript
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');
|
|
});
|
|
});
|