test: ripara la suite Vitest e migra gli e2e all'architettura attuale
La suite era allineata a una vecchia forma dello stato (sp.punt/sp.set/ sp.servHome) e a una vecchia architettura e2e (controller su :3001). Baseline iniziale: 77/170 test Vitest falliti. Vitest (ora 212/212 verdi): - gameState.test.js: riscritto con helper che derivano punteggio/set/ servizio dalla striscia; aggiunto blocco formInizio - server-utils.js: getNetworkIPs accetta interfacce iniettabili e printServerInfo accetta gli IP iniettabili (deterministico anche su WSL); filtro LAN unificato (esclude 127./169.254./172.) - websocket + stress: punteggio letto via punteggio(striscia) - ControllerPage/DisplayPage: forzato layout mobile (viewport portrait), punteggi impostati via striscia; aggiunto test bottone REFERTO - nuovi: referto.test.js, persist.test.js (mock fs), wsMixin.test.js, integration/server.test.js (routing) Refactor di supporto: - referto.js: estratta buildRefertoHtml(state, now) pura; generaReferto resta wrapper con window.open/print - server.js: estratti createApp()/startServer(); avvio solo se entrypoint e2e (migrazione parziale, NON ancora verificata verde): - tutti i riferimenti controller :3001 -> :3000/controller - forzato viewport portrait sul controller prima del goto - reset helper: chiude il dialog di configurazione che doReset apre - game-simulation: gestione del dialog SET VINTO automatico a 25
This commit is contained in:
+32
-13
@@ -9,7 +9,34 @@ function isWSL() {
|
||||
} catch { return false }
|
||||
}
|
||||
|
||||
export function getNetworkIPs() {
|
||||
// Un IPv4 è "pubblicabile" in LAN se non è loopback, link-local o bridge Docker.
|
||||
function isLanIPv4(address) {
|
||||
return !!address
|
||||
&& !address.startsWith('127.')
|
||||
&& !address.startsWith('169.254.')
|
||||
&& !address.startsWith('172.')
|
||||
}
|
||||
|
||||
// Estrae gli IP LAN da un oggetto in stile os.networkInterfaces().
|
||||
// Esportata per poter essere testata in isolamento, senza dipendere dalla piattaforma.
|
||||
export function collectIPs(nets) {
|
||||
const out = []
|
||||
for (const name of Object.keys(nets || {})) {
|
||||
for (const net of nets[name]) {
|
||||
if (net.family === 'IPv4' && !net.internal && isLanIPv4(net.address)) {
|
||||
out.push(net.address)
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Restituisce gli IP di rete della macchina.
|
||||
// Passando `nets` (oggetto in stile os.networkInterfaces) si forza il percorso
|
||||
// deterministico, scavalcando il rilevamento WSL/PowerShell: utile nei test.
|
||||
export function getNetworkIPs(nets) {
|
||||
if (nets) return collectIPs(nets)
|
||||
|
||||
if (isWSL()) {
|
||||
try {
|
||||
const out = execSync(
|
||||
@@ -18,23 +45,15 @@ export function getNetworkIPs() {
|
||||
)
|
||||
return out.toString().trim().split('\n')
|
||||
.map(s => s.trim())
|
||||
.filter(ip => ip && !ip.startsWith('127.') && !ip.startsWith('169.254.') && !ip.startsWith('172.'))
|
||||
.filter(isLanIPv4)
|
||||
} catch { return [] }
|
||||
}
|
||||
|
||||
const nets = networkInterfaces()
|
||||
const networkIPs = []
|
||||
for (const name of Object.keys(nets)) {
|
||||
for (const net of nets[name]) {
|
||||
if (net.family === 'IPv4' && !net.internal) networkIPs.push(net.address)
|
||||
}
|
||||
}
|
||||
return networkIPs
|
||||
return collectIPs(networkInterfaces())
|
||||
}
|
||||
|
||||
export function printServerInfo(port = 3000) {
|
||||
const networkIPs = getNetworkIPs()
|
||||
|
||||
// `networkIPs` è iniettabile per rendere la stampa testabile in modo deterministico.
|
||||
export function printServerInfo(port = 3000, networkIPs = getNetworkIPs()) {
|
||||
console.log(`\nSegnapunti Server`)
|
||||
console.log(` Display: http://127.0.0.1:${port}/display`)
|
||||
console.log(` Controller: http://127.0.0.1:${port}/controller`)
|
||||
|
||||
Reference in New Issue
Block a user