Skip to content

[Docs Site] Add tests for <head> tags #22051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2025
Merged
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
74 changes: 74 additions & 0 deletions worker/index.worker.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SELF } from "cloudflare:test";
import { describe, it, expect } from "vitest";
import { XMLParser } from "fast-xml-parser";
import { parse } from "node-html-parser";

describe("Cloudflare Docs", () => {
describe("html handling", () => {
Expand Down Expand Up @@ -300,4 +301,77 @@ describe("Cloudflare Docs", () => {
expect(await response.text()).toContain("Page not found.");
});
});

describe("head tags", async () => {
describe("/workers/", async () => {
const request = new Request("http://fakehost/workers/");
const response = await SELF.fetch(request);
expect(response.status).toBe(200);

const html = await response.text();
const dom = parse(html);

it("product meta tags", () => {
const product = dom.querySelector("meta[name='pcx_product']")
?.attributes.content;

const group = dom.querySelector("meta[name='pcx_content_group']")
?.attributes.content;

expect(product).toBe("Workers");
expect(group).toBe("Developer platform");
});

it("index.md rel='alternate' tag", () => {
const markdown = dom.querySelector(
"link[rel='alternate'][type='text/markdown']",
)?.attributes.href;

expect(markdown).toBe("/workers/index.md");
});

it("og:image tag", () => {
const image = dom.querySelector("meta[property='og:image']")?.attributes
.content;

expect(image).toBe(
"https://developers.cloudflare.com/dev-products-preview.png",
);
});
});

describe("/style-guide/fixtures/markdown/", async () => {
const request = new Request(
"http://fakehost/style-guide/fixtures/markdown/",
);
const response = await SELF.fetch(request);
expect(response.status).toBe(200);

const html = await response.text();
const dom = parse(html);

it("title", () => {
const title = dom.querySelector("title")?.textContent;

expect(title).toMatchInlineSnapshot(
`"Markdown · Cloudflare Style Guide"`,
);
});

it("description", () => {
const desc = dom.querySelector("meta[name='description']")?.attributes
.content;

const og = dom.querySelector("meta[property='og:description']")
?.attributes.content;

expect(desc).toMatchInlineSnapshot(
`"The HTML generated by this file is used as a test fixture for our Markdown generation."`,
);
expect(og).toMatchInlineSnapshot(
`"The HTML generated by this file is used as a test fixture for our Markdown generation."`,
);
});
});
});
});
Loading