Skip to content

Commit 8a6c828

Browse files
committed
[Docs Site] Add tests for <head> tags
1 parent 1104d1c commit 8a6c828

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

worker/index.worker.test.ts

Lines changed: 38 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,41 @@ describe("Cloudflare Docs", () => {
300301
expect(await response.text()).toContain("Page not found.");
301302
});
302303
});
304+
305+
describe("head tags", async () => {
306+
const request = new Request("http://fakehost/workers/");
307+
const response = await SELF.fetch(request);
308+
expect(response.status).toBe(200);
309+
310+
const html = await response.text();
311+
const dom = parse(html);
312+
313+
it("product meta tags", () => {
314+
const product = dom.querySelector("meta[name='pcx_product']")?.attributes
315+
.content;
316+
317+
const group = dom.querySelector("meta[name='pcx_content_group']")
318+
?.attributes.content;
319+
320+
expect(product).toBe("Workers");
321+
expect(group).toBe("Developer platform");
322+
});
323+
324+
it("index.md rel='alternate' tag", () => {
325+
const markdown = dom.querySelector(
326+
"link[rel='alternate'][type='text/markdown']",
327+
)?.attributes.href;
328+
329+
expect(markdown).toBe("/workers/index.md");
330+
});
331+
332+
it("og:image tag", () => {
333+
const image = dom.querySelector("meta[property='og:image']")?.attributes
334+
.content;
335+
336+
expect(image).toBe(
337+
"https://developers.cloudflare.com/dev-products-preview.png",
338+
);
339+
});
340+
});
303341
});

0 commit comments

Comments
 (0)