Files
AndreaSlopFotografie/web/config/lighthouserc.test.ts
T
SluijsensandClaude Opus 5.5 e4e7f8c82c Adds the URL rules to the preview server, IIS config and deploy
The preview server and web.config now follow the same URLs as nginx, without
the SPA fallback. Lighthouse exceptions need a recorded reason and the 404 page
is audited through an opt-in route. The deploy checks the build first and the
served result afterwards. The IIS rules stay unverified until a host exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 18:13:21 +01:00

146 lines
5.1 KiB
TypeScript

import fc from 'fast-check';
import { createRequire } from 'node:module';
import { describe, expect, it } from 'vitest';
import mobile from '../lighthouserc.cjs';
const require = createRequire(import.meta.url);
const desktop: {
ci: {
assert: { assertMatrix: Entry[] };
};
} = require('../lighthouserc.desktop.cjs');
type Entry = {
matchingUrlPattern: string;
assertions: Record<string, unknown>;
};
const matrix = (mobile.ci as { assert: { assertMatrix: Entry[] } }).assert
.assertMatrix;
const collect = (
mobile.ci as { collect: { url: string[]; numberOfRuns: number } }
).collect;
const startCommand = (mobile.ci as { collect: { startServerCommand: string } })
.collect.startServerCommand;
const matching = (entries: Entry[], url: string) =>
entries.filter((entry) => new RegExp(entry.matchingUrlPattern).test(url));
const exceptionEntries = Object.entries(mobile.mobileExceptions);
describe('mobiele uitzonderingen', () => {
it('hebben elk een besluit, een doel onder 0,9 en een bestaande pagina', () => {
expect(exceptionEntries.length).toBeGreaterThan(0);
for (const [path, { minScore, decision }] of exceptionEntries) {
expect(decision.trim()).not.toBe('');
expect(minScore).toBeLessThan(0.9);
expect(mobile.indexedPaths).toContain(path);
}
});
it('weigert een ongeldige uitzondering bij het laden', () => {
const paths = ['/', '/over-mij'];
const valid = { minScore: 0.85, decision: 'besluit' };
expect(() =>
mobile.validateExceptions({ '/over-mij': valid }, paths),
).not.toThrow();
expect(() =>
mobile.validateExceptions(
{ '/over-mij': { ...valid, decision: '' } },
paths,
),
).toThrow(/decision/);
expect(() =>
mobile.validateExceptions(
{ '/over-mij': { ...valid, minScore: 0.9 } },
paths,
),
).toThrow(/0\.9/);
expect(() =>
mobile.validateExceptions({ '/bestaat-niet': valid }, paths),
).toThrow(/unknown/);
});
});
describe('Lighthouse-configuratie', () => {
it('laat elke URL van de meting precies een matrixregel raken', () => {
expect(collect.url.length).toBeGreaterThan(0);
for (const url of collect.url) {
expect(matching(matrix, url), url).toHaveLength(1);
}
});
it('(invariant) dekt elke geindexeerde pagina precies een keer, voor elke deelverzameling uitzonderingen', () => {
fc.assert(
fc.property(
fc.subarray(exceptionEntries, { minLength: 0 }),
(subset) => {
const entries = mobile.buildIndexedEntries(
Object.fromEntries(subset),
mobile.indexedPaths,
);
for (const path of mobile.indexedPaths) {
const hits = matching(
entries as Entry[],
`http://localhost:4173${path}`,
);
expect(hits).toHaveLength(1);
}
},
),
);
});
it('geeft elke uitzondering haar eigen doel en de rest 0,9', () => {
for (const path of mobile.indexedPaths) {
const [entry] = matching(matrix, `http://localhost:4173${path}`);
const performance = entry.assertions['categories:performance'] as [
string,
{ minScore: number },
];
expect(performance[1].minScore).toBe(
mobile.mobileExceptions[path]?.minScore ?? 0.9,
);
}
});
it('houdt de 404-pagina buiten de pagina-lijsten', () => {
expect(mobile.indexedPaths).not.toContain(mobile.notFoundPath);
expect(mobile.noindexPaths).not.toContain(mobile.notFoundPath);
expect(mobile.notFoundPath).toBe('/__audit/404');
});
it('start de preview met de auditroute en meet een keer', () => {
expect(startCommand).toContain('--audit-route');
expect(collect.numberOfRuns).toBe(1);
});
it('eist kwaliteitscategorieen van 1 in elke regel die ze heeft', () => {
for (const entry of matrix) {
for (const key of [
'categories:accessibility',
'categories:best-practices',
'categories:seo',
]) {
if (key in entry.assertions) {
expect(entry.assertions[key]).toEqual([
'error',
{ minScore: 1 },
]);
}
}
}
});
it('zet op desktop elke prestatie-eis op 0,9', () => {
expect(desktop.ci.assert.assertMatrix).toHaveLength(matrix.length);
for (const entry of desktop.ci.assert.assertMatrix) {
expect(entry.assertions['categories:performance']).toEqual([
mobile.performanceLevel,
{ minScore: 0.9 },
]);
}
});
});