Files
paseo/packages/cli/src/utils/command-options.test.ts
T
Mohamed Boudra 047f40e623 Install npm plugins and review source updates (#4975)
* feat(plugins): unify source installation and simplify plugin settings

* feat(plugins): install npm sources and review CLI updates

Treat install selectors as one-time choices. Keep source identity separate from the installed revision, and resolve ordinary updates from the current upstream default. npm only acquires directories; plugin loading remains independent of npm.

* fix(plugins): preserve CLI diagnostics and exercise reviewed updates

Move new source capability coverage to real browser journeys. Update the requirements regression to exercise preview and apply, and preserve the existing duplicate-selector diagnostic across positional option scopes.

* test(plugins): remove unused pending helper

* test(plugins): pack registry fixtures with the Windows command runner

* test(plugins): assert failed client contribution setup

* docs(plugins): consolidate guides and document npm publishing

* docs(plugins): introduce publishing choices before npm instructions

* test(plugins): own browser journey cleanup in a fixture

* feat(plugins): prepare scaffolded packages for publishing
2026-09-17 10:22:20 +02:00

52 lines
1.6 KiB
TypeScript

import { Command } from "commander";
import { describe, expect, it } from "vitest";
import { createCli } from "../cli.js";
import { withGlobalOptions } from "./command-options.js";
async function parseHost(argv: string[]): Promise<string | undefined> {
const program = createCli().exitOverride();
let receivedHost: string | undefined;
program.commands
.find((command) => command.name() === "ls")!
.action(
withGlobalOptions((options: { host?: string }) => {
receivedHost = options.host;
}),
);
await program.parseAsync(argv, { from: "user" });
return receivedHost;
}
describe("global command options", () => {
it("passes a host declared before the command to its handler", async () => {
await expect(parseHost(["--host", "global:6767", "ls"])).resolves.toBe("global:6767");
});
it("preserves the command-local host position", async () => {
await expect(parseHost(["ls", "--host", "local:6767"])).resolves.toBe("local:6767");
});
it("rejects conflicting parent and command selectors", async () => {
await expect(
parseHost(["--host", "first:6767", "ls", "--host", "last:6767"]),
).rejects.toMatchObject({
code: "TARGET_AMBIGUOUS",
message: "Conflicting duplicate --host selectors.",
});
});
it("lets local-only commands ignore a global host", async () => {
const program = new Command().exitOverride().option("--host <host>");
let called = false;
program.command("status").action(() => {
called = true;
});
await program.parseAsync(["--host", "ignored:6767", "status"], { from: "user" });
expect(called).toBe(true);
});
});