
























@@ -0,0 +1,69 @@
1+import { Command } from "commander";
2+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
3+4+describe("plugins cli lazy runtime boundary", () => {
5+beforeEach(() => {
6+vi.resetModules();
7+});
8+9+afterEach(() => {
10+vi.doUnmock("./plugins-cli.runtime.js");
11+vi.resetModules();
12+});
13+14+it("renders parent help without importing the plugins runtime", async () => {
15+const runtimeLoaded = vi.fn();
16+vi.doMock("./plugins-cli.runtime.js", () => {
17+runtimeLoaded();
18+return {
19+runPluginMarketplaceListCommand: vi.fn(),
20+runPluginsDisableCommand: vi.fn(),
21+runPluginsDoctorCommand: vi.fn(),
22+runPluginsEnableCommand: vi.fn(),
23+runPluginsInstallAction: vi.fn(),
24+runPluginsRegistryCommand: vi.fn(),
25+};
26+});
27+28+const { registerPluginsCli } = await import("./plugins-cli.js");
29+const program = new Command();
30+program.exitOverride();
31+program.configureOutput({
32+writeErr: () => {},
33+writeOut: () => {},
34+});
35+registerPluginsCli(program);
36+37+await expect(program.parseAsync(["plugins", "--help"], { from: "user" })).rejects.toMatchObject(
38+{
39+exitCode: 0,
40+},
41+);
42+expect(runtimeLoaded).not.toHaveBeenCalled();
43+});
44+45+it("loads the plugins runtime for runtime-backed actions", async () => {
46+const runPluginsRegistryCommand = vi.fn().mockResolvedValue(undefined);
47+const runtimeLoaded = vi.fn();
48+vi.doMock("./plugins-cli.runtime.js", () => {
49+runtimeLoaded();
50+return {
51+runPluginMarketplaceListCommand: vi.fn(),
52+runPluginsDisableCommand: vi.fn(),
53+runPluginsDoctorCommand: vi.fn(),
54+runPluginsEnableCommand: vi.fn(),
55+runPluginsInstallAction: vi.fn(),
56+ runPluginsRegistryCommand,
57+};
58+});
59+60+const { registerPluginsCli } = await import("./plugins-cli.js");
61+const program = new Command();
62+registerPluginsCli(program);
63+64+await program.parseAsync(["plugins", "registry", "--json"], { from: "user" });
65+66+expect(runtimeLoaded).toHaveBeenCalledTimes(1);
67+expect(runPluginsRegistryCommand).toHaveBeenCalledWith(expect.objectContaining({ json: true }));
68+});
69+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。