Files
openclaw/src/config/io.parse.test.ts
2026-05-27 20:56:58 +01:00

23 lines
839 B
TypeScript

import { describe, expect, it, vi } from "vitest";
import { parseConfigJson5 } from "./config.js";
describe("parseConfigJson5", () => {
it("uses native JSON parsing before JSON5 fallback", () => {
const json5 = { parse: vi.fn(() => ({ fromJson5: true })) };
const result = parseConfigJson5('{"gateway":{"mode":"local"}}', json5);
expect(result).toEqual({ ok: true, parsed: { gateway: { mode: "local" } } });
expect(json5.parse).not.toHaveBeenCalled();
});
it("falls back to JSON5 for authored config syntax", () => {
const json5 = { parse: vi.fn(() => ({ gateway: { mode: "local" } })) };
const result = parseConfigJson5("{ gateway: { mode: 'local' } }", json5);
expect(result).toEqual({ ok: true, parsed: { gateway: { mode: "local" } } });
expect(json5.parse).toHaveBeenCalledOnce();
});
});