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 = '
';
const out = normalizeHtml(html);
expect(out).not.toMatch(/css-1abc|color:red|opmerking|\.a\{|stylesheet|AbCd1234\.js/);
expect(out).toContain('Hallo
\n\nwereld
'); 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(''), ); }); });