- Collegamento: corretta la SyntaxError di connection.js (una «let saved» dichiarata due
volte nello stesso blocco fermava tutta la pagina). Nuova prova ScriptSyntaxTests con un
controllo scritto in casa che legge ogni modulo di wwwroot: parentesi, dichiarazioni
doppie nello stesso blocco, importazioni che il modulo di arrivo non esporta.
- HEIF: il riconoscimento dei formati prende ogni marchio che HeifDecoder accetta (mif2,
MiHE, marchi solo compatibili), così rilevazione, decodifica, misure, miniatura e
impronta concordano.
- Docker, lasciare la pagina del browser: un nuovo contratto del browser cancella l'uscita
annotata (_leftAt) anche prima che la vista si riapra, e la copia della sessione aspetta
un altro comando del collegamento al più LetGoWait invece che senza limite.
- JPEG e PNG: senza EOI o IEND la decodifica fallisce («File danneggiato o incompleto»),
la sola lettura delle misure resta tollerante.
- Visualizzatore: IsDamaged legge prima l'intestazione e il file intero solo quando può
servire, in modo asincrono e con una piccola memoria per file, così una scheda con
molti file non blocca il server.
- Importazione (§9.3): le immagini danneggiate si importano come le altre ma si segnano
nella revisione, nel resoconto e nel CSV.
- Pulizia: le prove con il limite di 5 minuti non corrono più in parallelo fra loro.
- Pila dei caratteri come l'appendice B, senza Liberation; testo di Informazioni sulle
immagini fatte in casa; guida (Problemi comuni, Sicurezza) allineata all'uscita in
Docker dalla pagina del browser.
- docs/decisioni.md: le righe del 25 novembre 2026 con i motivi, compresa l'unione 537517b
tenuta così com'è.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
111 lines
6.0 KiB
C#
111 lines
6.0 KiB
C#
using Febe.Tests.Desktop.Support;
|
|
using Febe.Tests.Web.Support;
|
|
|
|
namespace Febe.Tests.Web;
|
|
|
|
/// <summary>
|
|
/// The modules of the interface load: a mistake that stops one module from parsing breaks every page importing it, and
|
|
/// the Chromium tests that would see it run only in the CI. <see cref="ScriptCheck"/> reads them without a browser.
|
|
/// </summary>
|
|
[TestClass]
|
|
public sealed class ScriptSyntaxTests
|
|
{
|
|
[TestMethod]
|
|
public void EveryModuleOfTheInterfaceReadsWithoutTheMistakesThatStopItLoading()
|
|
{
|
|
var root = Repository.PathOf("src", "Febe.Web", "wwwroot");
|
|
var files = Directory.GetFiles(root, "*.js", SearchOption.AllDirectories);
|
|
Assert.IsGreaterThan(30, files.Length, "the modules of the interface");
|
|
var problems = new List<string>();
|
|
foreach (var file in files)
|
|
{
|
|
var name = Path.GetRelativePath(root, file);
|
|
problems.AddRange(ScriptCheck.Problems(File.ReadAllText(file)).Select(p => $"{name}, {p}"));
|
|
}
|
|
|
|
Assert.IsEmpty(problems, string.Join(Environment.NewLine, problems));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void EveryStaticImportNamesSomethingTheOtherModuleExports()
|
|
{
|
|
var root = Repository.PathOf("src", "Febe.Web", "wwwroot");
|
|
var problems = new List<string>();
|
|
var checkedNames = 0;
|
|
foreach (var file in Directory.GetFiles(root, "*.js", SearchOption.AllDirectories))
|
|
{
|
|
foreach (var (from, names, line) in ScriptCheck.Imports(File.ReadAllText(file)))
|
|
{
|
|
if (!from.StartsWith('.'))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var target = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(file)!, from));
|
|
var where = $"{Path.GetRelativePath(root, file)}, riga {line}";
|
|
if (!File.Exists(target))
|
|
{
|
|
problems.Add($"{where}: «{from}» non esiste");
|
|
continue;
|
|
}
|
|
|
|
var exports = ScriptCheck.Exports(File.ReadAllText(target));
|
|
foreach (var name in names)
|
|
{
|
|
checkedNames++;
|
|
if (!exports.Contains(name))
|
|
{
|
|
problems.Add($"{where}: «{from}» non esporta «{name}»");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Assert.IsGreaterThan(50, checkedNames);
|
|
Assert.IsEmpty(problems, string.Join(Environment.NewLine, problems));
|
|
}
|
|
|
|
[TestMethod]
|
|
[DataRow("export function box(saved, page) {\n if (!saved) return null;\n let saved = null;\n}", "«saved» dichiarato di nuovo con let (già parametro", DisplayName = "parametro ridichiarato (connection.js, b29b35a)")]
|
|
[DataRow("const show = (value) => { const value = 1; };", "«value» dichiarato di nuovo", DisplayName = "parametro di una freccia")]
|
|
[DataRow("items.map(x => { let x = 2; return x; });", "«x» dichiarato di nuovo", DisplayName = "parametro senza parentesi")]
|
|
[DataRow("function f() { let a = 1; if (a) { let b; } const a = 2; }", "«a» dichiarato di nuovo con const", DisplayName = "due volte nello stesso blocco")]
|
|
[DataRow("import { h } from './dom.js';\nconst h = 1;", "«h» dichiarato di nuovo con const (già import", DisplayName = "nome già importato")]
|
|
[DataRow("class A { m(p) { class p {} } }", "«p» dichiarato di nuovo con class", DisplayName = "classe con il nome di un parametro")]
|
|
[DataRow("function f() { if (x) { return 1; }", "mai chiusa", DisplayName = "parentesi graffa mai chiusa")]
|
|
[DataRow("const a = [1, 2);", "chiude «[»", DisplayName = "parentesi che non corrispondono")]
|
|
[DataRow("const s = 'non chiusa;\n", "stringa non chiusa", DisplayName = "stringa non chiusa")]
|
|
[DataRow("const s = `a ${b} c;\n", "modello fra apici inversi non chiuso", DisplayName = "modello non chiuso")]
|
|
public void TheCheckFindsTheMistakesThatStopAModuleLoading(string source, string expected)
|
|
{
|
|
var problems = ScriptCheck.Problems(source);
|
|
Assert.IsTrue(problems.Any(p => p.Contains(expected, StringComparison.Ordinal)), string.Join(" | ", problems.DefaultIfEmpty("(nessuno)")));
|
|
}
|
|
|
|
[TestMethod]
|
|
[DataRow("export function box(saved, page) {\n let stored = null;\n const show = (value) => { stored = value; };\n}", DisplayName = "la correzione di connection.js")]
|
|
[DataRow("for (let i = 0; i < 3; i++) { let i2 = i; }\nfor (let i = 0; i < 3; i++) { const j = i; }", DisplayName = "variabili dei cicli")]
|
|
[DataRow("const re = /a{2}[/}]\\//g; const half = 4 / 2; const t = `x ${ { a: 1 }.a } ${`y ${1}`}`;", DisplayName = "espressioni regolari, divisioni e modelli annidati")]
|
|
[DataRow("function f(a) { { let a = 1; } if (a) { const a = 2; } }", DisplayName = "lo stesso nome in un blocco interno")]
|
|
[DataRow("const o = { let: 1, const: 2 }; o.let = o.const;", DisplayName = "proprietà con nomi di parole chiave")]
|
|
[DataRow("try { x(); } catch (error) { console.log(error); }\nconst error = 1;", DisplayName = "parametro di catch e nome fuori")]
|
|
[DataRow("// a comment with ' and ` and {\n/* and } */ const a = \"}\";", DisplayName = "commenti e stringhe con parentesi")]
|
|
public void TheCheckLeavesValidCodeAlone(string source)
|
|
{
|
|
var problems = ScriptCheck.Problems(source);
|
|
Assert.IsEmpty(problems, string.Join(" | ", problems));
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ImportsAndExportsAreReadByTheirNames()
|
|
{
|
|
var exports = ScriptCheck.Exports("export function a() {}\nexport async function b() {}\nexport const c = 1;\nexport class D {}\nconst e = 1, f = 2;\nexport { e, f as g };\nexport default a;");
|
|
CollectionAssert.AreEquivalent(new[] { "a", "b", "c", "D", "e", "g", "default" }, exports.ToArray());
|
|
var imports = ScriptCheck.Imports("import { a, b as c } from './x.js';\nimport * as y from './y.js';\nconst z = await import('./z.js');");
|
|
Assert.HasCount(2, imports);
|
|
Assert.AreEqual("./x.js", imports[0].From);
|
|
CollectionAssert.AreEqual(new[] { "a", "b" }, imports[0].Names);
|
|
Assert.IsEmpty(imports[1].Names);
|
|
}
|
|
}
|