Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion apps/storefront/scripts/seo-metadata.test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
import test from "node:test";
import { JSDOM } from "jsdom";

const appRoot = new URL("../", import.meta.url);

Expand Down Expand Up @@ -42,14 +43,30 @@ test("prerender emits complete CMS metadata in the first document response", asy
test("client SEO removes generated metadata without restoring stale tags", async () => {
const seo = await readFile(new URL("../../packages/ui/src/seo/Seo.tsx", appRoot), "utf8");

assert.match(seo, /querySelectorAll\([\s\S]*data-storefront-seo/);
assert.match(seo, /querySelectorAll\([\s\S]*data-storefront-seo\]:not\(\[data-rh\]\)/);
assert.doesNotMatch(seo, /insertBefore\(element/);
assert.match(seo, /image\?\.url \|\| opengraphImage/);
assert.match(seo, /property="og:image:alt"/);
assert.match(seo, /property="article:modified_time"/);
assert.match(seo, /name="twitter:image:alt"/);
});

test("client SEO cleanup preserves prerendered titles adopted by Helmet", () => {
const dom = new JSDOM(`<!doctype html><head>
<title data-storefront-seo data-rh="true">Adopted title</title>
<meta data-storefront-seo name="description" content="Stale description">
</head>`);

dom.window.document.head
.querySelectorAll(
'[data-storefront-seo]:not([data-rh]), meta[name="description"]:not([data-rh]), link[rel="canonical"]:not([data-rh])',
)
.forEach((element) => element.remove());

assert.equal(dom.window.document.title, "Adopted title");
assert.equal(dom.window.document.querySelector('meta[name="description"]'), null);
});

test("controlled crawler files remain exact and product feed uses its canonical address", async () => {
const prerender = await readFile(new URL("scripts/prerender.mjs", appRoot), "utf8");
const feedDiscovery = await readFile(new URL("src/components/GlobalFeedDiscovery.tsx", appRoot), "utf8");
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/seo/Seo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export function Seo({
useLayoutEffect(() => {
document.head
.querySelectorAll(
'[data-storefront-seo], meta[name="description"]:not([data-rh]), link[rel="canonical"]:not([data-rh])',
'[data-storefront-seo]:not([data-rh]), meta[name="description"]:not([data-rh]), link[rel="canonical"]:not([data-rh])',
)
.forEach((element) => element.remove());
}, []);
Expand Down
Loading