Skip to content
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