import { describe, expect, it } from 'vitest'; import { patchHtmlForIframe } from '@/lib/utils/iframe'; describe('patchHtmlForIframe', () => { it('injects the storage shim and sizing CSS after ', () => { const out = patchHtmlForIframe( 't', ); expect(out).toContain('data-iframe-storage-shim'); expect(out).toContain('data-iframe-patch'); }); it('runs the storage shim before the page scripts', () => { const html = ''; const out = patchHtmlForIframe(html); // The shim must appear before the page's own '; const out = patchHtmlForIframe(html); expect(out).toContain('data-iframe-error-shim'); // error shim runs first → before storage shim → before page scripts, so it // catches errors from everything that follows. expect(out.indexOf('data-iframe-error-shim')).toBeLessThan( out.indexOf('data-iframe-storage-shim'), ); expect(out.indexOf('data-iframe-storage-shim')).toBeLessThan(out.indexOf('boom()')); }); it('the error shim posts runtime errors (onerror / resource / rejection / console.error) to the parent', () => { const out = patchHtmlForIframe(''); const shim = out.match(/