import { describe, expect, it } from 'vitest'; import { firstDifferences, normalizeHtml } from './htmlBaseline.mjs'; describe('normalizeHtml', () => { it('keeps text, links, labels, meta, structured data and the data block', () => { const html = 'Titel' + '' + 'Over mij' + '' + ''; const out = normalizeHtml(html); for (const part of [ 'Titel', 'content="Tekst"', 'rel="canonical"', 'aria-label="Naar over mij"', 'Over mij', '{"a":1}', '{"b":2}', ]) { expect(out).toContain(part); } }); it('leaves out look and build details', () => { const html = '' + '' + '
tekst
' + ''; const out = normalizeHtml(html); expect(out).not.toMatch(/css-1abc|color:red|opmerking|\.a\{|stylesheet|AbCd1234\.js/); expect(out).toContain('
'); expect(out).toContain('/assets/foto.jpg'); expect(out).toContain(''); }); it('ignores formatting but notices a changed text', () => { const a = normalizeHtml('

Hallo

\n\n

wereld

'); const b = normalizeHtml('

Hallo

wereld

'); expect(a).toBe(b); expect(normalizeHtml('

Hallo

werelden

')).not.toBe(a); }); }); describe('firstDifferences', () => { it('reports the lines that differ and nothing for equal input', () => { expect(firstDifferences('a\nb', 'a\nb')).toEqual([]); const out = firstDifferences('a\nb\nc', 'a\nx\nc').join('\n'); expect(out).toContain('regel 2'); expect(out).toContain('basislijn: b'); expect(out).toContain('nu: x'); }); it('limits the number of reported differences', () => { const many = Array.from({ length: 20 }, (_, i) => `r${i}`).join('\n'); const other = Array.from({ length: 20 }, (_, i) => `s${i}`).join('\n'); expect(firstDifferences(many, other, 2)).toHaveLength(6); }); }); describe('normalizeHtml tags', () => { it('ignores line breaks and indentation inside a tag', () => { expect(normalizeHtml('')).toBe( normalizeHtml(''), ); }); });