import { describe, expect, it } from 'vitest'; import { buildSitemap } from './sitemap'; const xml = buildSitemap('https://pireon.dev', { pages: [ { id: 1, updated_at: '2026-09-27T20:36:14+00:00', alternates: { es: '/sobre-nosotros', en: '/en/about-us', ca: '/ca/qui-som', }, }, ], }, [ { id: 1, name: 'Angular', slug: 'angular', category: 'framework', projects_count: 0, members_count: 0, }, ]); describe('buildSitemap', () => { it('lists every language of a record as its own url', () => { for (const path of ['/sobre-nosotros', '/en/about-us', '/ca/qui-som']) { expect(xml).toContain(`https://pireon.dev${path}`); } }); it('states every language on each url, with the default as x-default', () => { expect(xml).toContain( 'hreflang="en" href="https://pireon.dev/en/about-us"', ); expect(xml).toContain( 'hreflang="x-default" href="https://pireon.dev/sobre-nosotros"', ); expect(xml).toContain('2026-09-27T20:36:14+00:00'); }); it('includes the landing and the listings this site composes', () => { expect(xml).toContain('https://pireon.dev/'); // `&` escaped, as XML requires. expect(xml).toContain('https://pireon.dev/?lang=en'); expect(xml).toContain('https://pireon.dev/radar'); expect(xml).toContain('https://pireon.dev/ca/col-labora'); }); // The API gives technologies no address and `/slugs` cannot carry them, so // these are composed here and have to be in the sitemap all the same. it('includes the technology pages this site composes', () => { expect(xml).toContain('https://pireon.dev/tecnologias/angular'); expect(xml).toContain( 'https://pireon.dev/en/technologies/angular', ); expect(xml).toContain( 'https://pireon.dev/ca/tecnologies/angular', ); expect(xml).toContain( 'hreflang="ca" href="https://pireon.dev/ca/tecnologies/angular"', ); }); it('is a well-formed document', () => { const document = new DOMParser().parseFromString(xml, 'application/xml'); expect(document.getElementsByTagName('parsererror')).toHaveLength(0); }); });