mirror of
https://github.com/moltbot/moltbot.git
synced 2026-03-08 06:54:24 +00:00
test(scripts): dedupe a2ui temp fixture and cover skip-missing env path
This commit is contained in:
@@ -5,24 +5,45 @@ import { describe, expect, it } from "vitest";
|
||||
import { copyA2uiAssets } from "../../scripts/canvas-a2ui-copy.js";
|
||||
|
||||
describe("canvas a2ui copy", () => {
|
||||
it("throws a helpful error when assets are missing", async () => {
|
||||
async function withA2uiFixture(run: (dir: string) => Promise<void>) {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-a2ui-"));
|
||||
|
||||
try {
|
||||
await expect(copyA2uiAssets({ srcDir: dir, outDir: path.join(dir, "out") })).rejects.toThrow(
|
||||
'Run "pnpm canvas:a2ui:bundle"',
|
||||
);
|
||||
await run(dir);
|
||||
} finally {
|
||||
await fs.rm(dir, { recursive: true, force: true });
|
||||
}
|
||||
}
|
||||
|
||||
it("throws a helpful error when assets are missing", async () => {
|
||||
await withA2uiFixture(async (dir) => {
|
||||
await expect(copyA2uiAssets({ srcDir: dir, outDir: path.join(dir, "out") })).rejects.toThrow(
|
||||
'Run "pnpm canvas:a2ui:bundle"',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("skips missing assets when OPENCLAW_A2UI_SKIP_MISSING=1", async () => {
|
||||
await withA2uiFixture(async (dir) => {
|
||||
const previous = process.env.OPENCLAW_A2UI_SKIP_MISSING;
|
||||
process.env.OPENCLAW_A2UI_SKIP_MISSING = "1";
|
||||
try {
|
||||
await expect(
|
||||
copyA2uiAssets({ srcDir: dir, outDir: path.join(dir, "out") }),
|
||||
).resolves.toBeUndefined();
|
||||
} finally {
|
||||
if (previous === undefined) {
|
||||
delete process.env.OPENCLAW_A2UI_SKIP_MISSING;
|
||||
} else {
|
||||
process.env.OPENCLAW_A2UI_SKIP_MISSING = previous;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("copies bundled assets to dist", async () => {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-a2ui-"));
|
||||
const srcDir = path.join(dir, "src");
|
||||
const outDir = path.join(dir, "dist");
|
||||
|
||||
try {
|
||||
await withA2uiFixture(async (dir) => {
|
||||
const srcDir = path.join(dir, "src");
|
||||
const outDir = path.join(dir, "dist");
|
||||
await fs.mkdir(srcDir, { recursive: true });
|
||||
await fs.writeFile(path.join(srcDir, "index.html"), "<html></html>", "utf8");
|
||||
await fs.writeFile(path.join(srcDir, "a2ui.bundle.js"), "console.log(1);", "utf8");
|
||||
@@ -31,8 +52,6 @@ describe("canvas a2ui copy", () => {
|
||||
|
||||
await expect(fs.stat(path.join(outDir, "index.html"))).resolves.toBeTruthy();
|
||||
await expect(fs.stat(path.join(outDir, "a2ui.bundle.js"))).resolves.toBeTruthy();
|
||||
} finally {
|
||||
await fs.rm(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user