mirror of https://github.com/openclaw/openclaw.git
51 lines
2.0 KiB
TypeScript
51 lines
2.0 KiB
TypeScript
import { execFileSync } from "node:child_process";
|
|
import path from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { resolveExtensionTestPlan } from "../../scripts/test-extension.mjs";
|
|
|
|
const scriptPath = path.join(process.cwd(), "scripts", "test-extension.mjs");
|
|
|
|
function readPlan(args: string[], cwd = process.cwd()) {
|
|
const stdout = execFileSync(process.execPath, [scriptPath, ...args, "--dry-run", "--json"], {
|
|
cwd,
|
|
encoding: "utf8",
|
|
});
|
|
return JSON.parse(stdout) as ReturnType<typeof resolveExtensionTestPlan>;
|
|
}
|
|
|
|
describe("scripts/test-extension.mjs", () => {
|
|
it("resolves channel-root extensions onto the channel vitest config", () => {
|
|
const plan = resolveExtensionTestPlan({ targetArg: "slack", cwd: process.cwd() });
|
|
|
|
expect(plan.extensionId).toBe("slack");
|
|
expect(plan.extensionDir).toBe("extensions/slack");
|
|
expect(plan.config).toBe("vitest.channels.config.ts");
|
|
expect(plan.testFiles.some((file) => file.startsWith("extensions/slack/"))).toBe(true);
|
|
});
|
|
|
|
it("resolves provider extensions onto the extensions vitest config", () => {
|
|
const plan = resolveExtensionTestPlan({ targetArg: "firecrawl", cwd: process.cwd() });
|
|
|
|
expect(plan.extensionId).toBe("firecrawl");
|
|
expect(plan.config).toBe("vitest.extensions.config.ts");
|
|
expect(plan.testFiles.some((file) => file.startsWith("extensions/firecrawl/"))).toBe(true);
|
|
});
|
|
|
|
it("includes paired src roots when they contain tests", () => {
|
|
const plan = resolveExtensionTestPlan({ targetArg: "line", cwd: process.cwd() });
|
|
|
|
expect(plan.roots).toContain("extensions/line");
|
|
expect(plan.roots).toContain("src/line");
|
|
expect(plan.config).toBe("vitest.channels.config.ts");
|
|
expect(plan.testFiles.some((file) => file.startsWith("src/line/"))).toBe(true);
|
|
});
|
|
|
|
it("infers the extension from the current working directory", () => {
|
|
const cwd = path.join(process.cwd(), "extensions", "slack");
|
|
const plan = readPlan([], cwd);
|
|
|
|
expect(plan.extensionId).toBe("slack");
|
|
expect(plan.extensionDir).toBe("extensions/slack");
|
|
});
|
|
});
|