import { describe, expect, it } from 'vitest'; import { findRenderer, renderers } from '../index'; import type { ResponseBody } from '../../../shared/client'; describe('findRenderer', () => { it('routes null body to the empty renderer', () => { expect(findRenderer('text/plain', null).id).toBe('empty'); }); it('routes binary-too-large bodies to the binary-too-large renderer', () => { const body: ResponseBody = { kind: 'binary-too-large', size: 9_999_999 }; expect(findRenderer('image/png', body).id).toBe('binary-too-large'); }); it('routes image/svg+xml strings to the svg renderer (not the image renderer)', () => { expect(findRenderer('image/svg+xml', '').id).toBe('svg'); }); it('routes image/png binary bodies to the image renderer', () => { const body: ResponseBody = { kind: 'binary', base64: 'AQID' }; expect(findRenderer('image/png', body).id).toBe('image'); }); it('routes image/jpeg binary bodies to the image renderer', () => { const body: ResponseBody = { kind: 'binary', base64: 'AQID' }; expect(findRenderer('image/jpeg', body).id).toBe('image'); }); it('routes non-image binary bodies to the binary renderer', () => { const body: ResponseBody = { kind: 'binary', base64: 'AQID' }; expect(findRenderer('application/pdf', body).id).toBe('binary'); expect(findRenderer('application/octet-stream', body).id).toBe('binary'); expect(findRenderer('font/woff2', body).id).toBe('binary'); expect(findRenderer('audio/mpeg', body).id).toBe('binary'); expect(findRenderer('video/mp4', body).id).toBe('binary'); expect(findRenderer('application/zip', body).id).toBe('binary'); }); it('routes JSON content-types to the json renderer', () => { expect(findRenderer('application/json', '{}').id).toBe('json'); expect(findRenderer('application/json; charset=utf-8', '{}').id).toBe( 'json', ); expect(findRenderer('application/ld+json', '{}').id).toBe('json'); }); it('routes text/html (and its charset/case variants) to the html renderer', () => { expect(findRenderer('text/html', '
').id).toBe('html'); expect(findRenderer('text/html; charset=utf-8', '').id).toBe('html'); // Case-insensitive — proves we use normalizeContentType, not startsWith. expect(findRenderer('text/HTML', '').id).toBe('html'); // Empty-string HTML body is still claimed by html (matcher is // content-type-driven; the renderer happily produces a blank iframe). expect(findRenderer('text/html', '').id).toBe('html'); }); it('routes XML content-types (and RFC 7303 +xml variants) to the xml renderer', () => { expect(findRenderer('application/xml', '