|
| 1 | +// Fixture Common tests cover shared E2E fixture file/assertion helpers. |
| 2 | +import { readFileSync } from "node:fs"; |
| 3 | +import path from "node:path"; |
| 4 | +import { afterEach, describe, expect, it } from "vitest"; |
| 5 | +import { |
| 6 | +assert, |
| 7 | +json, |
| 8 | +readJson, |
| 9 | +requireArg, |
| 10 | +write, |
| 11 | +writeJson, |
| 12 | +} from "../../scripts/e2e/lib/fixtures/common.mjs"; |
| 13 | +import { cleanupTempDirs, makeTempDir } from "../helpers/temp-dir.js"; |
| 14 | + |
| 15 | +const tempDirs: string[] = []; |
| 16 | + |
| 17 | +afterEach(() => { |
| 18 | +cleanupTempDirs(tempDirs); |
| 19 | +}); |
| 20 | + |
| 21 | +describe("fixture common helpers", () => { |
| 22 | +it("writes nested text and formatted JSON files", () => { |
| 23 | +const root = makeTempDir(tempDirs, "openclaw-fixture-common-"); |
| 24 | +const textPath = path.join(root, "nested", "fixture.txt"); |
| 25 | +const jsonPath = path.join(root, "config", "fixture.json"); |
| 26 | + |
| 27 | +write(textPath, "contents"); |
| 28 | +writeJson(jsonPath, { enabled: true, nested: { value: 1 } }); |
| 29 | + |
| 30 | +expect(readFileSync(textPath, "utf8")).toBe("contents"); |
| 31 | +expect(readFileSync(jsonPath, "utf8")).toBe( |
| 32 | +`${JSON.stringify({ enabled: true, nested: { value: 1 } }, null, 2)}\n`, |
| 33 | +); |
| 34 | +expect(readJson(jsonPath)).toEqual({ enabled: true, nested: { value: 1 } }); |
| 35 | +expect(json({ ok: true })).toBe(`${JSON.stringify({ ok: true }, null, 2)}\n`); |
| 36 | +}); |
| 37 | + |
| 38 | +it("rejects missing required arguments and failed assertions", () => { |
| 39 | +expect(requireArg("value", "field")).toBe("value"); |
| 40 | +expect(() => requireArg("", "field")).toThrow("field is required"); |
| 41 | +expect(() => assert(false, "fixture failed")).toThrow("fixture failed"); |
| 42 | +expect(() => assert(true, "fixture failed")).not.toThrow(); |
| 43 | +}); |
| 44 | +}); |