With contactForm.enabled=true the e2e and Lighthouse runs asked a token route that CI does not have (404, console error, run 666). The preview server gets an opt-in --contact-stub (token 200 without captcha, submit 202); the e2e server helper and the Lighthouse start command switch it on. Tests that need another answer still replace it per page with page.route. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
148 lines
5.2 KiB
TypeScript
148 lines
5.2 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');
|
|
// CI heeft geen CMS-host: de preview bootst de contact-API na
|
|
expect(startCommand).toContain('--contact-stub');
|
|
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 },
|
|
]);
|
|
}
|
|
});
|
|
});
|