mirror of
https://github.com/morluto/rea.git
synced 2026-11-21 14:05:49 +00:00
test(website): consolidate generated site verification checks (#12783)
test(website): consolidate verifier and fallback coverage
This commit is contained in:
1 parent
49f78bd03b
commit
e17434945f
2 files changed
+35
-39
No files matched your search
+33
-34
@@ -306,8 +306,9 @@ class WebsiteSearchChecks(unittest.TestCase):
|
||||
},
|
||||
)
|
||||
nested.rename(site / "moved.html")
|
||||
self.assertIn("https://rea.tools/moved.html", urls())
|
||||
self.assertNotIn("https://rea.tools/guides/new/", urls())
|
||||
moved = urls()
|
||||
self.assertIn("https://rea.tools/moved.html", moved)
|
||||
self.assertNotIn("https://rea.tools/guides/new/", moved)
|
||||
(site / "moved.html").unlink()
|
||||
self.assertNotIn("https://rea.tools/moved.html", urls())
|
||||
|
||||
@@ -319,31 +320,25 @@ class WebsiteSearchChecks(unittest.TestCase):
|
||||
"index.html",
|
||||
'rel="canonical" href="https://rea.tools/"',
|
||||
'rel="canonical" href="https://morluto.github.io/rea/"',
|
||||
"head canonical",
|
||||
"needs exactly one head canonical",
|
||||
),
|
||||
(
|
||||
"faq/index.html",
|
||||
'hreflang="zh-CN" href="https://rea.tools/zh-CN/faq/"',
|
||||
'hreflang="zh-CN" href="https://[::1/faq/"',
|
||||
"invalid URL",
|
||||
"invalid hreflang URL",
|
||||
),
|
||||
(
|
||||
"showcase/aegis/index.html",
|
||||
'rel="canonical" href="https://rea.tools/showcase/aegis/"',
|
||||
'rel="canonical" href="https://rea.tools/"',
|
||||
"head canonical",
|
||||
),
|
||||
(
|
||||
"examples/notes-electron/index.html",
|
||||
'content="noindex"',
|
||||
'content="index"',
|
||||
"must have a head noindex",
|
||||
"needs exactly one head canonical",
|
||||
),
|
||||
(
|
||||
"sitemap.xml",
|
||||
"https://rea.tools/faq/",
|
||||
"https://rea.tools/deleted/",
|
||||
"each indexable page once",
|
||||
"must contain each indexable page once",
|
||||
),
|
||||
(
|
||||
"faq/index.html",
|
||||
@@ -352,25 +347,27 @@ class WebsiteSearchChecks(unittest.TestCase):
|
||||
"twitter:card",
|
||||
),
|
||||
)
|
||||
for name, old, new, message in cases:
|
||||
with self.subTest(name=name), tempfile.TemporaryDirectory() as directory:
|
||||
site = Path(directory) / "public"
|
||||
shutil.copytree(ROOT / "website/_site", site)
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
site = Path(directory) / "public"
|
||||
shutil.copytree(ROOT / "website/_site", site)
|
||||
for name, old, new, _ in cases:
|
||||
path = site / name
|
||||
source = path.read_text()
|
||||
self.assertIn(old, source)
|
||||
path.write_text(source.replace(old, new, 1))
|
||||
self.assertTrue(
|
||||
any(message in error for error in VERIFY.check_site(site)[3])
|
||||
)
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
site = Path(directory) / "public"
|
||||
shutil.copytree(ROOT / "website/_site", site)
|
||||
(site / "assets/social-card.png").unlink()
|
||||
self.assertIn(
|
||||
"Social preview PNG is missing; run scripts/prepare-website.py",
|
||||
VERIFY.check_site(site)[3],
|
||||
)
|
||||
diagnostics = "\n".join(VERIFY.check_site(site)[3])
|
||||
for name, _, _, message in cases:
|
||||
with self.subTest(name=name, message=message):
|
||||
self.assertIn(f"{name}: {message}", diagnostics)
|
||||
self.assertIn("Social preview PNG is missing", diagnostics)
|
||||
|
||||
# Changing the indexable set would also invalidate the sitemap.
|
||||
example = site / "examples/notes-electron/index.html"
|
||||
source = example.read_text()
|
||||
self.assertIn('content="noindex"', source)
|
||||
example.write_text(source.replace('content="noindex"', 'content="index"', 1))
|
||||
self.assertIn(f"{example.relative_to(site).as_posix()}: example application must have a head noindex directive", VERIFY.check_site(site)[3])
|
||||
|
||||
|
||||
class WebsiteMaintenanceChecks(unittest.TestCase):
|
||||
@@ -541,16 +538,18 @@ class WebsiteMaintenanceChecks(unittest.TestCase):
|
||||
page = site / "faq/index.html"
|
||||
original = page.read_text()
|
||||
cases = (
|
||||
('<a href="https://rea.tools/deleted/">Broken</a>', "missing local target"),
|
||||
('<code>https://rea.tools/guides/native/#deleted</code>', "missing HTML fragment"),
|
||||
('<code>https://morluto.github.io/rea/examples/notes-web/</code>', "obsolete website URL"),
|
||||
('<button data-copy="deleted">Copy</button>', "missing copy target"),
|
||||
('<a href="https://[">Malformed</a>', "invalid URL"),
|
||||
('<a href="https://rea.tools/deleted/">Broken</a>', "missing local target: https://rea.tools/deleted/"),
|
||||
('<code>https://rea.tools/guides/native/#deleted</code>', "missing HTML fragment: https://rea.tools/guides/native/#deleted"),
|
||||
('<code>https://morluto.github.io/rea/examples/notes-web/</code>', "obsolete website URL: https://morluto.github.io/rea/examples/notes-web/"),
|
||||
('<button data-copy="deleted">Copy</button>', "missing copy target: deleted"),
|
||||
('<a href="https://[">Malformed</a>', "invalid URL 'https://[':"),
|
||||
)
|
||||
for inserted, message in cases:
|
||||
inserted = "".join(html for html, _ in cases)
|
||||
page.write_text(original.replace("</main>", inserted + "</main>", 1))
|
||||
diagnostics = "\n".join(VERIFY.check_site(site)[3])
|
||||
for _, message in cases:
|
||||
with self.subTest(message=message):
|
||||
page.write_text(original.replace("</main>", inserted + "</main>", 1))
|
||||
self.assertTrue(any(message in error for error in VERIFY.check_site(site)[3]))
|
||||
self.assertIn(f"{page.relative_to(site)}: {message}", diagnostics)
|
||||
|
||||
def test_repository_links_preserve_targets_and_containment_through_aliased_roots(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
|
||||
@@ -2,12 +2,11 @@ import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import worker from "./worker.mjs";
|
||||
|
||||
function assets({ markdownStatus = 200, requests } = {}) {
|
||||
function assets({ markdownStatus = 200 } = {}) {
|
||||
return {
|
||||
ASSETS: {
|
||||
async fetch(request) {
|
||||
const url = new URL(request.url);
|
||||
requests?.push(url.pathname);
|
||||
const markdown = url.pathname.endsWith("index.md");
|
||||
if (url.pathname === "/missing/")
|
||||
return new Response("Missing", { status: 404 });
|
||||
@@ -106,18 +105,16 @@ await test("HEAD and validators use the selected representation", async () => {
|
||||
});
|
||||
|
||||
await test("missing Markdown keeps HTML, and asset redirects and missing routes survive", async () => {
|
||||
const requests = [];
|
||||
const html = await worker.fetch(
|
||||
new Request("https://rea.tools/guide/", {
|
||||
headers: { Accept: "text/markdown" },
|
||||
}),
|
||||
assets({ markdownStatus: 404, requests }),
|
||||
assets({ markdownStatus: 404 }),
|
||||
);
|
||||
assert.equal(html.status, 200);
|
||||
assert.equal(html.headers.get("Content-Type"), "text/html");
|
||||
assert.equal(html.headers.get("ETag"), '"html"');
|
||||
assert.equal(await html.text(), "<h1>Guide</h1>");
|
||||
assert.deepEqual(requests, ["/guide/", "/guide/index.md"]);
|
||||
for (const [path, status] of [
|
||||
["/guide", 307],
|
||||
["/missing/", 404],
|
||||
|
||||
Reference in new issue
Block a user