Files
docs/test/projects.spec.ts
naomi b718aa650b
Node.js CI / Lint and Test (push) Successful in 58s
Security Scan / Security Audit (push) Failing after 5m2s
feat: overhaul many things (#17)
### Explanation

_No response_

### Issue

_No response_

### Attestations

- [ ] I have read and agree to the [Code of Conduct](https://docs.nhcarrigan.com/community/coc/)
- [ ] I have read and agree to the [Community Guidelines](https://docs.nhcarrigan.com/community/guide/).
- [ ] My contribution complies with the [Contributor Covenant](https://docs.nhcarrigan.com/dev/covenant/).

### Dependencies

- [ ] I have pinned the dependencies to a specific patch version.

### Style

- [ ] I have run the linter and resolved any errors.
- [ ] My pull request uses an appropriate title, matching the conventional commit standards.
- [ ] My scope of feat/fix/chore/etc. correctly matches the nature of changes in my pull request.

### Tests

- [ ] My contribution adds new code, and I have added tests to cover it.
- [ ] My contribution modifies existing code, and I have updated the tests to reflect these changes.
- [ ] All new and existing tests pass locally with my changes.
- [ ] Code coverage remains at or above the configured threshold.

### Documentation

_No response_

### Versioning

_No response_

Reviewed-on: #17
Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com>
Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
2025-12-16 06:15:26 +01:00

72 lines
2.4 KiB
TypeScript

/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { readFile } from "node:fs/promises";
import { readdir } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
import matter from "gray-matter";
interface Project {
avatar?: string;
category: string;
description: string;
name: string;
premium: boolean;
url?: string;
wip: boolean;
}
const getProjects = async(): Promise<Array<Project>> => {
const request = await fetch("https://data.nhcarrigan.com/projects.json");
const data = await request.json();
return data as Array<Project>;
};
const projectNameMap: Record<string, string> = {
"Naomi's Blog": "blog",
"NHCarrigan Documentation": "docs",
"Naomi's VSCode Themes": "vscode-themes",
"Artists4Palestine Bot": "a4p-bot",
"ESLint Config": "eslint-config",
"Naomi's Adventure I: An Isekai Story": "naomis-adventure-i",
};
const excludedProjects = new Set<string>([
"Translation Service",
"Gitea"
]);
const convertTitleCaseToKebabCase = (string_: string): string => {
return string_.toLowerCase().replace(/\s+/g, "-").replaceAll(/[:']/g, "");
};
describe("projects documentation", () => {
it("should include all public projects", {timeout: 10000}, async() => {
expect.hasAssertions();
const projects = await getProjects();
const docs = await readdir(join(__dirname, "..", "src", "content", "docs", "projects"));
for (const project of projects) {
if (excludedProjects.has(project.name)) {
continue;
}
const page = docs.find((d) => {
return project.name in projectNameMap
? d.split(".")[0] === projectNameMap[project.name]
: d.split(".")[0] === convertTitleCaseToKebabCase(project.name);
});
expect(page, `Page not found for project ${project.name}`).toBeDefined();
const content = await readFile(join(__dirname, "..", "src", "content", "docs", "projects", page!), "utf-8");
const { data } = matter(content);
expect(data.title, `Title not found for project ${project.name}`).toBeDefined();
expect(data.title, `Title for project ${project.name} is not correct`).toBe(project.name);
if (project.wip) {
continue;
}
expect(content).not.toMatch(/:::note\nThis section is coming soon!\n:::/);
}
});
});