feat: add image to PDF converter
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
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 { registerImageToPdfConverter } from '../../src/converters/imageToPdf.js';
|
||||
import { resolve, listTargetFormats } from '../../src/converters/registry.js';
|
||||
import { detectInputMime } from '../../src/mime.js';
|
||||
|
||||
let tmpDir;
|
||||
|
||||
beforeAll(async () => {
|
||||
registerImageToPdfConverter();
|
||||
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'converter-image-to-pdf-'));
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await fs.rm(tmpDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
describe('image to PDF converter', () => {
|
||||
it('registers pdf as a target for every image format', () => {
|
||||
expect(listTargetFormats('png')).toContain('pdf');
|
||||
expect(listTargetFormats('jpg')).toContain('pdf');
|
||||
});
|
||||
|
||||
it('converts a PNG fixture into a valid PDF', async () => {
|
||||
const inputPath = path.join(import.meta.dirname, '..', 'fixtures', 'sample.png');
|
||||
const outputPath = path.join(tmpDir, 'output.pdf');
|
||||
const entry = resolve('png', 'pdf');
|
||||
|
||||
await entry.convert(inputPath, outputPath);
|
||||
|
||||
const detected = await detectInputMime(outputPath);
|
||||
expect(detected.mime).toBe('application/pdf');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user