feat(test): add test for code block mpapings

This commit is contained in:
Elian Doran 2025-02-16 11:42:14 +02:00
parent a8f9403990
commit 952ec516ee
No known key found for this signature in database
2 changed files with 23 additions and 2 deletions

View File

@ -0,0 +1,21 @@
import { describe, expect, it } from "vitest";
import { getStylesDirectory, readThemesFromFileSystem } from "./code_block_theme.js";
import themeNames from "./code_block_theme_names.json" with { type: "json" };
describe("Code block theme", () => {
it("all themes are mapped", () => {
const themes = readThemesFromFileSystem(getStylesDirectory());
const mappedThemeNames = new Set(Object.values(themeNames));
const unmappedThemeNames = new Set<string>();
for (const theme of themes) {
if (!mappedThemeNames.has(theme.title)) {
unmappedThemeNames.add(theme.title);
}
}
expect(unmappedThemeNames.size, `Unmapped themes: ${Array.from(unmappedThemeNames).join(", ")}`).toBe(0);
});
});

View File

@ -44,7 +44,7 @@ export function listSyntaxHighlightingThemes() {
};
}
function getStylesDirectory() {
export function getStylesDirectory() {
if (isElectron && !isDev) {
return "styles";
}
@ -60,7 +60,7 @@ function getStylesDirectory() {
* @param path the path to read from. Usually this is the highlight.js `styles` directory.
* @returns the list of themes.
*/
function readThemesFromFileSystem(path: string): ColorTheme[] {
export function readThemesFromFileSystem(path: string): ColorTheme[] {
return fs
.readdirSync(path)
.filter((el) => el.endsWith(".min.css"))