mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-21 10:01:37 -06:00
568b920b21
* refactor(imports): dedupe and hoist imports * feat(lint): enforce import/no-duplicates and import/first
37 lines
1.5 KiB
TypeScript
37 lines
1.5 KiB
TypeScript
import fs, { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
import { pathToFileURL } from "node:url";
|
|
import { describe, expect, it } from "vitest";
|
|
import { resolveMxcLauncherPath } from "../src/plugin-root.js";
|
|
|
|
describe("resolveMxcLauncherPath", () => {
|
|
it("throws when called from outside any plugin tree", () => {
|
|
const outside = pathToFileURL(path.resolve("README.md")).href;
|
|
expect(() => resolveMxcLauncherPath(outside)).toThrow(/cannot locate plugin root/);
|
|
});
|
|
|
|
it("returns the src .mjs in dev layout", () => {
|
|
const launcher = resolveMxcLauncherPath();
|
|
expect(launcher).toMatch(/mxc-spawn-launcher\.mjs$/);
|
|
expect(fs.existsSync(launcher)).toBe(true);
|
|
});
|
|
|
|
it("returns the package dist launcher in packed plugin layout", () => {
|
|
const root = mkdtempSync(path.join(tmpdir(), "mxc-packed-plugin-"));
|
|
try {
|
|
writeFileSync(path.join(root, "package.json"), "{}");
|
|
writeFileSync(path.join(root, "openclaw.plugin.json"), "{}");
|
|
const distDir = path.join(root, "dist");
|
|
fs.mkdirSync(distDir, { recursive: true });
|
|
const launcher = path.join(distDir, "mxc-spawn-launcher.mjs");
|
|
writeFileSync(launcher, "export {};\n");
|
|
const moduleUrl = pathToFileURL(path.join(distDir, "index.js")).href;
|
|
|
|
expect(resolveMxcLauncherPath(moduleUrl)).toBe(launcher);
|
|
} finally {
|
|
rmSync(root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
});
|