Skip to content

Commit 2993fad

Browse files
authored
[Docs Site] Add tests for <head> tags (#22051)
* [Docs Site] Add tests for <head> tags * add title and desc tests
1 parent 95ab48d commit 2993fad

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

worker/index.worker.test.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SELF } from "cloudflare:test";
22
import { describe, it, expect } from "vitest";
33
import { XMLParser } from "fast-xml-parser";
4+
import { parse } from "node-html-parser";
45

56
describe("Cloudflare Docs", () => {
67
describe("html handling", () => {
@@ -300,4 +301,77 @@ describe("Cloudflare Docs", () => {
300301
expect(await response.text()).toContain("Page not found.");
301302
});
302303
});
304+
305+
describe("head tags", async () => {
306+
describe("/workers/", async () => {
307+
const request = new Request("http://fakehost/workers/");
308+
const response = await SELF.fetch(request);
309+
expect(response.status).toBe(200);
310+
311+
const html = await response.text();
312+
const dom = parse(html);
313+
314+
it("product meta tags", () => {
315+
const product = dom.querySelector("meta[name='pcx_product']")
316+
?.attributes.content;
317+
318+
const group = dom.querySelector("meta[name='pcx_content_group']")
319+
?.attributes.content;
320+
321+
expect(product).toBe("Workers");
322+
expect(group).toBe("Developer platform");
323+
});
324+
325+
it("index.md rel='alternate' tag", () => {
326+
const markdown = dom.querySelector(
327+
"link[rel='alternate'][type='text/markdown']",
328+
)?.attributes.href;
329+
330+
expect(markdown).toBe("/workers/index.md");
331+
});
332+
333+
it("og:image tag", () => {
334+
const image = dom.querySelector("meta[property='og:image']")?.attributes
335+
.content;
336+
337+
expect(image).toBe(
338+
"https://developers.cloudflare.com/dev-products-preview.png",
339+
);
340+
});
341+
});
342+
343+
describe("/style-guide/fixtures/markdown/", async () => {
344+
const request = new Request(
345+
"http://fakehost/style-guide/fixtures/markdown/",
346+
);
347+
const response = await SELF.fetch(request);
348+
expect(response.status).toBe(200);
349+
350+
const html = await response.text();
351+
const dom = parse(html);
352+
353+
it("title", () => {
354+
const title = dom.querySelector("title")?.textContent;
355+
356+
expect(title).toMatchInlineSnapshot(
357+
`"Markdown · Cloudflare Style Guide"`,
358+
);
359+
});
360+
361+
it("description", () => {
362+
const desc = dom.querySelector("meta[name='description']")?.attributes
363+
.content;
364+
365+
const og = dom.querySelector("meta[property='og:description']")
366+
?.attributes.content;
367+
368+
expect(desc).toMatchInlineSnapshot(
369+
`"The HTML generated by this file is used as a test fixture for our Markdown generation."`,
370+
);
371+
expect(og).toMatchInlineSnapshot(
372+
`"The HTML generated by this file is used as a test fixture for our Markdown generation."`,
373+
);
374+
});
375+
});
376+
});
303377
});

0 commit comments

Comments
 (0)