@@ -470,6 +470,32 @@ describe("package commands", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("allows explicit self-update checks when automatic version checks are disabled", async () => {
|
||||
const previousSkipVersionCheck = process.env.PI_SKIP_VERSION_CHECK;
|
||||
process.env.PI_SKIP_VERSION_CHECK = "1";
|
||||
const fetchMock = vi.fn(async () => Response.json({ version: VERSION }));
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
const logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
|
||||
try {
|
||||
await expect(runPackageCommandDirectly(["update", "--self"])).resolves.toBeUndefined();
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledOnce();
|
||||
expect(logSpy.mock.calls.map(([message]) => String(message)).join("\n")).toContain(
|
||||
`pi is already up to date (v${VERSION})`,
|
||||
);
|
||||
expect(errorSpy).not.toHaveBeenCalled();
|
||||
expect(process.exitCode).toBeUndefined();
|
||||
} finally {
|
||||
if (previousSkipVersionCheck === undefined) {
|
||||
delete process.env.PI_SKIP_VERSION_CHECK;
|
||||
} else {
|
||||
process.env.PI_SKIP_VERSION_CHECK = previousSkipVersionCheck;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it("uses the update check version for forced self updates even when current", async () => {
|
||||
const globalPrefix = join(tempDir, "global-prefix");
|
||||
const projectPrefix = join(tempDir, "project-prefix");
|
||||
|
||||
@@ -80,12 +80,21 @@ describe("version checks", () => {
|
||||
await expect(getLatestPiRelease("1.2.3")).resolves.toEqual({ note: "**Read this**", version: "1.2.4" });
|
||||
});
|
||||
|
||||
it("skips api calls when version checks are disabled", async () => {
|
||||
it("skips automatic api calls when version checks are disabled", async () => {
|
||||
process.env.PI_SKIP_VERSION_CHECK = "1";
|
||||
const fetchMock = vi.fn();
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
|
||||
await expect(getLatestPiVersion("1.2.3")).resolves.toBeUndefined();
|
||||
await expect(checkForNewPiVersion("1.2.3")).resolves.toBeUndefined();
|
||||
expect(fetchMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("allows direct api calls when automatic version checks are disabled", async () => {
|
||||
process.env.PI_SKIP_VERSION_CHECK = "1";
|
||||
const fetchMock = vi.fn(async () => Response.json({ version: "1.2.4" }));
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
|
||||
await expect(getLatestPiVersion("1.2.3")).resolves.toBe("1.2.4");
|
||||
expect(fetchMock).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user