lume-plugin-kroki/tests/mod.test.ts

90 lines
2.1 KiB
TypeScript
Raw Permalink Normal View History

2024-11-07 20:24:21 -05:00
/*
* Copyright 2024 Foster Hangdaan
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import mod from "../mod.ts";
import { getSite } from "./utils.ts";
import {
assertExists,
assertInstanceOf,
assertSnapshot,
valibot,
} from "../deps.ts";
2024-11-07 20:24:21 -05:00
Deno.test("Error thrown on invalid options", async (t) => {
await t.step("Invalid server", () => {
let error;
try {
mod({ server: "invalid domain" });
} catch (err) {
error = err;
}
assertExists(error);
assertInstanceOf(error, valibot.ValiError);
2024-11-07 20:24:21 -05:00
});
await t.step("Invalid enabledDiagrams", () => {
let error;
try {
mod({ enabledDiagrams: ["invalid diagram"] });
} catch (err) {
error = err;
}
assertExists(error);
assertInstanceOf(error, valibot.ValiError);
2024-11-07 20:24:21 -05:00
});
await t.step("Invalid format", () => {
let error;
try {
// @ts-ignore: This is supposed to be an invalid value.
mod({ format: "invalid" });
} catch (err) {
error = err;
}
assertExists(error);
assertInstanceOf(error, valibot.ValiError);
2024-11-07 20:24:21 -05:00
});
});
Deno.test("Lume Site", async (t) => {
const site = getSite();
site.use(mod());
// Don't save the site to disk.
site.addEventListener("beforeSave", () => false);
await site.build();
site.pages.sort((a, b) => {
if (a.outputPath > b.outputPath) {
return 1;
} else if (a.outputPath < b.outputPath) {
return -1;
} else {
return 0;
}
});
await assertSnapshot(t, {
src: site.pages.map((page) => ({
path: page.src.path,
ext: page.src.ext,
})),
content: site.pages.map((page) => page.content),
});
});