44 lines
1.6 KiB
TypeScript
44 lines
1.6 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import {
|
|
getFrontmatterString,
|
|
normalizeStringList,
|
|
parseFrontmatterBool,
|
|
resolveOpenClawManifestBlock,
|
|
} from "./frontmatter.js";
|
|
|
|
describe("shared/frontmatter", () => {
|
|
test("normalizeStringList handles strings and arrays", () => {
|
|
expect(normalizeStringList("a, b,,c")).toEqual(["a", "b", "c"]);
|
|
expect(normalizeStringList([" a ", "", "b"])).toEqual(["a", "b"]);
|
|
expect(normalizeStringList(null)).toEqual([]);
|
|
});
|
|
|
|
test("getFrontmatterString extracts strings only", () => {
|
|
expect(getFrontmatterString({ a: "b" }, "a")).toBe("b");
|
|
expect(getFrontmatterString({ a: 1 }, "a")).toBeUndefined();
|
|
});
|
|
|
|
test("parseFrontmatterBool respects fallback", () => {
|
|
expect(parseFrontmatterBool("true", false)).toBe(true);
|
|
expect(parseFrontmatterBool("false", true)).toBe(false);
|
|
expect(parseFrontmatterBool(undefined, true)).toBe(true);
|
|
});
|
|
|
|
test("resolveOpenClawManifestBlock parses JSON5 metadata and picks openclaw block", () => {
|
|
const frontmatter = {
|
|
metadata: "{ openclaw: { foo: 1, bar: 'baz' } }",
|
|
};
|
|
expect(resolveOpenClawManifestBlock({ frontmatter })).toEqual({ foo: 1, bar: "baz" });
|
|
});
|
|
|
|
test("resolveOpenClawManifestBlock returns undefined for invalid input", () => {
|
|
expect(resolveOpenClawManifestBlock({ frontmatter: {} })).toBeUndefined();
|
|
expect(
|
|
resolveOpenClawManifestBlock({ frontmatter: { metadata: "not-json5" } }),
|
|
).toBeUndefined();
|
|
expect(
|
|
resolveOpenClawManifestBlock({ frontmatter: { metadata: "{ nope: { a: 1 } }" } }),
|
|
).toBeUndefined();
|
|
});
|
|
});
|