mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-17 04:50:51 +00:00
test: tighten json file helper coverage
This commit is contained in:
@@ -15,6 +15,15 @@ describe("json-file helpers", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("returns undefined when the target path is a directory", async () => {
|
||||
await withTempDir({ prefix: "openclaw-json-file-" }, async (root) => {
|
||||
const pathname = path.join(root, "config-dir");
|
||||
fs.mkdirSync(pathname);
|
||||
|
||||
expect(loadJsonFile(pathname)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
it("creates parent dirs, writes a trailing newline, and loads the saved object", async () => {
|
||||
await withTempDir({ prefix: "openclaw-json-file-" }, async (root) => {
|
||||
const pathname = path.join(root, "nested", "config.json");
|
||||
@@ -30,4 +39,15 @@ describe("json-file helpers", () => {
|
||||
expect(dirMode).toBe(0o700);
|
||||
});
|
||||
});
|
||||
|
||||
it("overwrites existing JSON files with the latest payload", async () => {
|
||||
await withTempDir({ prefix: "openclaw-json-file-" }, async (root) => {
|
||||
const pathname = path.join(root, "config.json");
|
||||
fs.writeFileSync(pathname, '{"enabled":false}\n', "utf8");
|
||||
|
||||
saveJsonFile(pathname, { enabled: true, count: 2 });
|
||||
|
||||
expect(loadJsonFile(pathname)).toEqual({ enabled: true, count: 2 });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user