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

87 lines
2.2 KiB
TypeScript
Raw 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";
2024-11-08 17:55:50 -05:00
import { valibot as v } from "../deps.ts";
2024-11-08 17:42:43 -05:00
import { assertExists, assertInstanceOf } from "@std/assert";
import { assertSnapshot } from "@std/testing/snapshot";
import { getSite } from "./utils.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);
2024-11-08 17:55:50 -05:00
assertInstanceOf(error, v.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);
2024-11-08 17:55:50 -05:00
assertInstanceOf(error, v.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);
2024-11-08 17:55:50 -05:00
assertInstanceOf(error, v.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),
});
});