





























@@ -41,6 +41,26 @@ function expectParsedGitSpec(spec: string) {
4141return parsed;
4242}
434344+function firstCommandRun(): unknown[] | undefined {
45+return runCommandWithTimeoutMock.mock.calls[0];
46+}
47+48+function firstInstallOptions():
49+| {
50+expectedPluginId?: string;
51+packageDir?: string;
52+installPolicyRequest?: { kind?: string; requestedSpecifier?: string };
53+}
54+| undefined {
55+return installPluginFromInstalledPackageDirMock.mock.calls[0]?.[0] as
56+| {
57+expectedPluginId?: string;
58+packageDir?: string;
59+installPolicyRequest?: { kind?: string; requestedSpecifier?: string };
60+}
61+| undefined;
62+}
63+4464describe("parseGitPluginSpec", () => {
4565it("normalizes GitHub shorthand and ref selectors", () => {
4666const explicitRef = expectParsedGitSpec("git:github.com/acme/demo@v1.2.3");
@@ -100,7 +120,7 @@ describe("installPluginFromGitSpec", () => {
100120expect(result.git.url).toBe("https://github.com/acme/demo.git");
101121expect(result.git.ref).toBe("v1.2.3");
102122expect(result.git.commit).toBe("abc123");
103-const cloneArgv = runCommandWithTimeoutMock.mock.calls.at(0)?.[0] as string[];
123+const cloneArgv = firstCommandRun()?.[0] as string[];
104124expect(cloneArgv.slice(0, 3)).toEqual(["git", "clone", "https://github.com/acme/demo.git"]);
105125expect(cloneArgv[3]).toContain("/repo");
106126expect(runCommandWithTimeoutMock.mock.calls.at(1)?.[0]).toEqual([
@@ -118,13 +138,7 @@ describe("installPluginFromGitSpec", () => {
118138"--no-audit",
119139"--no-fund",
120140]);
121-const installOptions = installPluginFromInstalledPackageDirMock.mock.calls.at(0)?.[0] as
122-| {
123-expectedPluginId?: string;
124-packageDir?: string;
125-installPolicyRequest?: { kind?: string; requestedSpecifier?: string };
126-}
127-| undefined;
141+const installOptions = firstInstallOptions();
128142expect(installOptions?.expectedPluginId).toBe("demo");
129143expect(installOptions?.packageDir).toContain("/repo");
130144expect(installOptions?.installPolicyRequest?.kind).toBe("plugin-git");
@@ -157,7 +171,7 @@ describe("installPluginFromGitSpec", () => {
157171throw new Error(result.error);
158172}
159173160-const cloneArgv = runCommandWithTimeoutMock.mock.calls.at(0)?.[0] as string[];
174+const cloneArgv = firstCommandRun()?.[0] as string[];
161175expect(cloneArgv.slice(0, 5)).toEqual([
162176"git",
163177"clone",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。