Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 6 additions & 6 deletions tests/markdown.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test, describe } from "bun:test";
import fs from "fs";
import path from "path";
import fs from "node:fs";
import path from "node:path";

const rootDir: string = path.join(__dirname, "../");

Expand All @@ -17,15 +17,15 @@ describe("Markdown Rendering", () => {
});

test("Pages Rendered", () => {
mdFiles.forEach((file) => {
for (const file of mdFiles) {
Copy link
Contributor

@trflynn89 trflynn89 Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please write some notes in the commit message as to why these are best practices. The for loops feel like 6 of one, half a dozen of the other to me.

const htmlFile = file.replace(".mdx", "/index.html");
const htmlFilePath = path.join(distDir, htmlFile);
expect(fs.existsSync(htmlFilePath)).toBe(true);
});
};
});

test("Layouts Applied", () => {
mdFiles.forEach((file) => {
for (const file of mdFiles) {
const htmlFile = file.replace(".mdx", "/index.html");
const htmlFilePath = path.join(distDir, htmlFile);
const htmlContent = fs.readFileSync(htmlFilePath, "utf-8");
Expand All @@ -37,6 +37,6 @@ describe("Markdown Rendering", () => {
const h1Tag = `>${frontMatterTitle}</h1>`;

expect(htmlContent.includes(h1Tag)).toBe(true);
});
};
});
});
8 changes: 4 additions & 4 deletions tests/newsletters.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, test, describe } from "bun:test";
import fs from "fs";
import path from "path";
import fs from "node:fs";
import path from "node:path";

const rootDir: string = path.join(__dirname, "../");

Expand All @@ -13,7 +13,7 @@ describe("Newsletters", () => {
.filter((file) => file.endsWith(".mdx"));

test("Draft pages should be excluded in build", async () => {
mdFiles.forEach((file) => {
for (const file of mdFiles) {
const filePath = path.join(srcDir, file);
const htmlFile = file.replace(".mdx", "/index.html");
const htmlFilePath = path.join(distDir, htmlFile);
Expand All @@ -24,6 +24,6 @@ describe("Newsletters", () => {
} else {
expect(fs.existsSync(htmlFilePath)).toBe(true);
}
});
};
});
});
8 changes: 4 additions & 4 deletions tests/rss.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect, describe } from "bun:test";
import { XMLParser } from "fast-xml-parser";
import fs from "fs";
import path from "path";
import fs from "node:fs";
import path from "node:path";

const rootDir: string = path.join(__dirname, "../");

Expand Down Expand Up @@ -34,7 +34,7 @@ describe("RSS Feeds", () => {
return !fileContent.includes("type: Hidden");
});
expect(parsedXML.rss.channel.item).toBeArrayOfSize(nonHiddenMdFiles.length);
parsedXML.rss.channel.item.forEach((item: any) => {
for (const item of parsedXML.rss.channel.item) {
const itemAttributes = Object.keys(item);
expect(itemAttributes).toEqual(
expect.arrayContaining([
Expand All @@ -46,6 +46,6 @@ describe("RSS Feeds", () => {
"category",
])
);
});
};
});
});
20 changes: 10 additions & 10 deletions tests/urls.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from "fs";
import path from "path";
import fs from "node:fs";
import path from "node:path";
import { test, expect, describe } from "bun:test";

const srcDir: string = path.join(__dirname, "../src");
Expand All @@ -13,12 +13,12 @@ describe("URL Compliance", () => {
(file) =>
file.endsWith(".mdx") || file.endsWith(".ts") || file.endsWith(".astro")
);
files.forEach((file) => {
for (const file of files) {
const content = fs.readFileSync(path.join(srcDir, file), "utf-8");
const base = content.match(/assets\//g);
const proper = content.match(/\/assets\//g);
expect(base?.length ?? 0).toBe(proper?.length ?? 0);
});
};
});

test("Only allow secure outside URLs, properly declared locals, and mailto:", () => {
Expand All @@ -28,17 +28,17 @@ describe("URL Compliance", () => {
(file) =>
file.endsWith(".mdx") || file.endsWith(".ts") || file.endsWith(".astro")
);
files.forEach((file) => {
for (const file of files) {
const content = fs.readFileSync(path.join(srcDir, file), "utf-8");
const hrefs = content.match(/href="([^"]*)"/g) || [];
// Only allow secure outside URLs, properly declared locals, and mailto:
hrefs.forEach((href) => {
for (const href of hrefs) {
expect(
href.startsWith('href="https://') ||
href.startsWith('href="/') ||
href.startsWith('href="mailto:')
href.startsWith('href="/') ||
href.startsWith('href="mailto:')
).toBe(true);
});
});
}
};
});
});