import { describe, expect, it } from 'vitest'; import { injectHeroPreload } from './heroPreload.ts'; const page = (body: string, head = 't') => `${head}${body}`; describe('injectHeroPreload', () => { it('writes the preload of the first photo between markers before ', () => { const out = injectHeroPreload( page( '', ), ); expect(out).toContain( 't', ); }); it('finds the image when src comes before class', () => { const out = injectHeroPreload( page(''), ); expect(out).toContain('href="/a.jpg"'); }); it('leaves a page without a hero, without a head and a done page alone', () => { const plain = page(''); expect(injectHeroPreload(plain)).toBe(plain); const noHead = ''; expect(injectHeroPreload(noHead)).toBe(noHead); const once = injectHeroPreload( page(''), ); expect(injectHeroPreload(once)).toBe(once); }); });