feat: add MIME sniffing and output MIME lookup
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Vendored
BIN
Binary file not shown.
|
After Width: | Height: | Size: 68 B |
@@ -0,0 +1,27 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import path from 'node:path';
|
||||
import { detectInputMime, outputMimeType } from '../src/mime.js';
|
||||
|
||||
describe('detectInputMime', () => {
|
||||
it('detects PNG from magic bytes regardless of file extension', async () => {
|
||||
const fixturePath = path.join(import.meta.dirname, 'fixtures', 'sample.png');
|
||||
|
||||
const result = await detectInputMime(fixturePath);
|
||||
|
||||
expect(result).toEqual({ ext: 'png', mime: 'image/png' });
|
||||
});
|
||||
});
|
||||
|
||||
describe('outputMimeType', () => {
|
||||
it('returns the MIME type for a known target format', () => {
|
||||
expect(outputMimeType('pdf')).toBe('application/pdf');
|
||||
expect(outputMimeType('png')).toBe('image/png');
|
||||
expect(outputMimeType('docx')).toBe(
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
|
||||
);
|
||||
});
|
||||
|
||||
it('throws for an unknown target format', () => {
|
||||
expect(() => outputMimeType('made-up-format')).toThrowError(/made-up-format/);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user