feat: add converter registry
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { register, resolve, listTargetFormats, _resetForTests } from '../../src/converters/registry.js';
|
||||
|
||||
beforeEach(() => {
|
||||
_resetForTests();
|
||||
});
|
||||
|
||||
describe('converter registry', () => {
|
||||
it('resolves a registered source/target pair', () => {
|
||||
const convert = async () => {};
|
||||
register({ family: 'image', sourceFormat: 'png', targetFormat: 'webp', convert });
|
||||
|
||||
const entry = resolve('png', 'webp');
|
||||
|
||||
expect(entry.family).toBe('image');
|
||||
expect(entry.convert).toBe(convert);
|
||||
});
|
||||
|
||||
it('returns null for an unregistered pair', () => {
|
||||
expect(resolve('png', 'made-up')).toBeNull();
|
||||
});
|
||||
|
||||
it('lists all target formats registered for a source format', () => {
|
||||
register({ family: 'image', sourceFormat: 'png', targetFormat: 'webp', convert: async () => {} });
|
||||
register({ family: 'image', sourceFormat: 'png', targetFormat: 'jpg', convert: async () => {} });
|
||||
register({ family: 'document', sourceFormat: 'docx', targetFormat: 'pdf', convert: async () => {} });
|
||||
|
||||
expect(listTargetFormats('png').sort()).toEqual(['jpg', 'webp']);
|
||||
expect(listTargetFormats('docx')).toEqual(['pdf']);
|
||||
expect(listTargetFormats('unknown-format')).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user