mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
test(scripts): route fixture common helper
This commit is contained in:
@@ -1581,6 +1581,7 @@ const TOOLING_SOURCE_TEST_TARGETS = new Map([
|
||||
],
|
||||
],
|
||||
["scripts/e2e/lib/fixtures/config.mjs", ["test/scripts/fixture-config.test.ts"]],
|
||||
["scripts/e2e/lib/fixtures/common.mjs", ["test/scripts/fixture-common.test.ts"]],
|
||||
["scripts/e2e/lib/fixtures/mock-openai-config.mjs", ["test/scripts/mock-openai-config.test.ts"]],
|
||||
["scripts/e2e/lib/fixtures/plugins.mjs", ["test/scripts/fixture-plugin-commands.test.ts"]],
|
||||
[
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
// Fixture Common tests cover shared E2E fixture file/assertion helpers.
|
||||
import { readFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import {
|
||||
assert,
|
||||
json,
|
||||
readJson,
|
||||
requireArg,
|
||||
write,
|
||||
writeJson,
|
||||
} from "../../scripts/e2e/lib/fixtures/common.mjs";
|
||||
import { cleanupTempDirs, makeTempDir } from "../helpers/temp-dir.js";
|
||||
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
afterEach(() => {
|
||||
cleanupTempDirs(tempDirs);
|
||||
});
|
||||
|
||||
describe("fixture common helpers", () => {
|
||||
it("writes nested text and formatted JSON files", () => {
|
||||
const root = makeTempDir(tempDirs, "openclaw-fixture-common-");
|
||||
const textPath = path.join(root, "nested", "fixture.txt");
|
||||
const jsonPath = path.join(root, "config", "fixture.json");
|
||||
|
||||
write(textPath, "contents");
|
||||
writeJson(jsonPath, { enabled: true, nested: { value: 1 } });
|
||||
|
||||
expect(readFileSync(textPath, "utf8")).toBe("contents");
|
||||
expect(readFileSync(jsonPath, "utf8")).toBe(
|
||||
`${JSON.stringify({ enabled: true, nested: { value: 1 } }, null, 2)}\n`,
|
||||
);
|
||||
expect(readJson(jsonPath)).toEqual({ enabled: true, nested: { value: 1 } });
|
||||
expect(json({ ok: true })).toBe(`${JSON.stringify({ ok: true }, null, 2)}\n`);
|
||||
});
|
||||
|
||||
it("rejects missing required arguments and failed assertions", () => {
|
||||
expect(requireArg("value", "field")).toBe("value");
|
||||
expect(() => requireArg("", "field")).toThrow("field is required");
|
||||
expect(() => assert(false, "fixture failed")).toThrow("fixture failed");
|
||||
expect(() => assert(true, "fixture failed")).not.toThrow();
|
||||
});
|
||||
});
|
||||
@@ -522,6 +522,7 @@ describe("scripts/test-projects changed-target routing", () => {
|
||||
],
|
||||
],
|
||||
["scripts/e2e/lib/fixtures/config.mjs", ["test/scripts/fixture-config.test.ts"]],
|
||||
["scripts/e2e/lib/fixtures/common.mjs", ["test/scripts/fixture-common.test.ts"]],
|
||||
[
|
||||
"scripts/e2e/lib/fixtures/mock-openai-config.mjs",
|
||||
["test/scripts/mock-openai-config.test.ts"],
|
||||
|
||||
Reference in New Issue
Block a user