Files
Studio_Grasso/tests/helpers/site.ts
T
Claude 601d13cfaf test: suite completa di §11 e npm run verify verde
- html-validate su tutte le pagine; linkinator su astro preview (link, asset,
  CSS e ancore), con modalità --external per i siti esterni
- e2e Playwright: struttura e metadati di ogni pagina, 404, navigazione,
  sottomenu, menu mobile, ancore del vecchio sito, nessuna richiesta esterna,
  nessun cookie, localStorage vuoto, mappa solo dopo il clic, funzionamento
  senza JavaScript, modulo di contatto
- a11y: axe su tutte le pagine a 1440 e 390 px e negli stati interattivi,
  tastiera (skip link, sottomenu, menu mobile), focus visibile, testo al 200 %,
  reflow a 320 px, movimento ridotto
- check-compliance.mjs: P.IVA, link legali, risorse sicure, segnaposto,
  JSON-LD, sitemap, robots, .htaccess, badge e servizi, uso di
  «commercialista», riferimento L. 4/2013, budget
- fix: punti di interruzione in em, focus ciclico nel menu mobile,
  rel="noopener" sui link esterni del Markdown, numeri di telefono non spezzabili

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016zJ9ZWGKvoKoxYwbmnRKdJ
2026-10-15 22:55:46 +00:00

68 lines
2.5 KiB
TypeScript

/**
* Supporto ai test: elenco delle pagine letto dalla sitemap generata in dist/ (nessuna lista da
* tenere allineata a mano), URL del sito e utilità comuni.
*/
import { existsSync, readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import type { Page } from '@playwright/test';
export const SITE = (process.env.SITE_URL || 'https://www.grassoezio.it').replace(/\/+$/, '');
const DIST = resolve(import.meta.dirname, '..', '..', 'dist');
function locs(xml: string): string[] {
return [...xml.matchAll(/<loc>([^<]+)<\/loc>/g)].map((m) => m[1].trim());
}
/** Percorsi delle pagine elencate nella sitemap (es. «/», «/studio/»). */
export function sitemapPaths(): string[] {
const index = resolve(DIST, 'sitemap-index.xml');
if (!existsSync(index)) {
throw new Error('Sitemap non trovata in dist/: eseguire `npm run build` prima dei test.');
}
const paths: string[] = [];
for (const sitemap of locs(readFileSync(index, 'utf8'))) {
const file = resolve(DIST, new URL(sitemap).pathname.replace(/^\//, ''));
for (const url of locs(readFileSync(file, 'utf8'))) paths.push(new URL(url).pathname);
}
return [...new Set(paths)].sort();
}
/** Pagine generate ma escluse dalla sitemap (noindex). */
export const EXTRA_PAGES = ['/404.html', '/contatti/grazie/'];
export const PAGES = sitemapPaths();
export const ALL_PAGES = [...PAGES, ...EXTRA_PAGES];
export const SERVICE_PAGES = PAGES.filter((p) => /^\/servizi\/[^/]+\/$/.test(p));
/** Vero per le richieste che restano sul server locale di test. */
export function isLocalRequest(url: string): boolean {
const u = new URL(url);
if (u.protocol === 'data:' || u.protocol === 'blob:' || u.protocol === 'about:') return true;
return u.hostname === '127.0.0.1' || u.hostname === 'localhost';
}
/** Raccoglie errori della console e della pagina. */
export function collectConsoleErrors(page: Page): string[] {
const errors: string[] = [];
page.on('console', (msg) => {
if (msg.type() === 'error') errors.push(msg.text());
});
page.on('pageerror', (err) => errors.push(err.message));
return errors;
}
/** Risposta finta per Google Maps: nei test nessuna richiesta esce dalla macchina. */
export async function stubGoogle(page: Page): Promise<string[]> {
const requested: string[] = [];
await page.route('https://www.google.com/**', (route) => {
requested.push(route.request().url());
return route.fulfill({
status: 200,
contentType: 'text/html',
body: '<!doctype html><title>Mappa</title>',
});
});
return requested;
}