Skip to content

Commit 3ef57d6

Browse files
committed
[Docs Site] Add tests for <head> tags
1 parent de71097 commit 3ef57d6

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", () => {
@@ -291,4 +292,41 @@ describe("Cloudflare Docs", () => {
291292
expect(await response.text()).toContain("Page not found.");
292293
});
293294
});
295+
296+
describe("head tags", async () => {
297+
const request = new Request("http://fakehost/workers/");
298+
const response = await SELF.fetch(request);
299+
expect(response.status).toBe(200);
300+
301+
const html = await response.text();
302+
const dom = parse(html);
303+
304+
it("product meta tags", () => {
305+
const product = dom.querySelector("meta[name='pcx_product']")?.attributes
306+
.content;
307+
308+
const group = dom.querySelector("meta[name='pcx_content_group']")
309+
?.attributes.content;
310+
311+
expect(product).toBe("Workers");
312+
expect(group).toBe("Developer platform");
313+
});
314+
315+
it("index.md rel='alternate' tag", () => {
316+
const markdown = dom.querySelector(
317+
"link[rel='alternate'][type='text/markdown']",
318+
)?.attributes.href;
319+
320+
expect(markdown).toBe("/workers/index.md");
321+
});
322+
323+
it("og:image tag", () => {
324+
const image = dom.querySelector("meta[property='og:image']")?.attributes
325+
.content;
326+
327+
expect(image).toBe(
328+
"https://developers.cloudflare.com/dev-products-preview.png",
329+
);
330+
});
331+
});
294332
});

0 commit comments

Comments
 (0)