mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-17 21:10:54 +00:00
Tests: add extension test runner
This commit is contained in:
50
test/scripts/test-extension.test.ts
Normal file
50
test/scripts/test-extension.test.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
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");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user