Files
WRNexusJS/packages/cli/test/plugin-command.test.ts
Clintchiz 586a6db8ff
Quality / quality (ubuntu-latest) (push) Failing after 21s
Quality / quality (windows-latest) (push) Canceled after 0s
release: WRNexusJS 0.8.0
2026-08-02 23:18:51 +05:30

33 lines
1.1 KiB
TypeScript

import { afterEach, expect, test } from "bun:test";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { runPluginCliCommand } from "../src/plugin-command.ts";
const roots: string[] = [];
afterEach(() => {
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true });
delete (globalThis as Record<string, unknown>).__pluginCommandArgs;
});
test("application plugins can register executable CLI commands", async () => {
const root = mkdtempSync(join(tmpdir(), "wrnexus-plugin-command-"));
roots.push(root);
writeFileSync(
join(root, "wrnexus.config.ts"),
`export default {
plugins: [{
name: "command-test",
cliCommands: [{
name: "greet",
run(args) { globalThis.__pluginCommandArgs = args }
}]
}]
};
`,
);
expect(await runPluginCliCommand(root, "greet", ["Ada"])).toBe(true);
expect((globalThis as Record<string, unknown>).__pluginCommandArgs).toEqual(["Ada"]);
expect(await runPluginCliCommand(root, "missing", [])).toBe(false);
});