mirror of
https://github.com/Pandipipas/scoreko-electron-dev.git
synced 2026-06-06 05:32:06 +00:00
Improving Installer and Updater Process
This commit is contained in:
@@ -56,3 +56,38 @@ test("downloadInstaller rejects insecure production download URLs", async () =>
|
||||
/unsupported protocol/,
|
||||
);
|
||||
});
|
||||
|
||||
test("downloadInstaller reuses existing file if size matches and does not download again", async () => {
|
||||
const tempDirectory = fs.mkdtempSync(path.join(os.tmpdir(), "scoreko-update-download-"));
|
||||
const downloadDirectory = path.join(tempDirectory, "scoreko-updates");
|
||||
fs.mkdirSync(downloadDirectory, { recursive: true });
|
||||
|
||||
const installerPath = path.join(downloadDirectory, "Scoreko_setup_0.2.0.exe");
|
||||
fs.writeFileSync(installerPath, "cached-installer-bytes");
|
||||
const cachedSize = fs.statSync(installerPath).size;
|
||||
|
||||
const previousFetch = globalThis.fetch;
|
||||
globalThis.fetch = async () => {
|
||||
throw new Error("Should not fetch when using cached file!");
|
||||
};
|
||||
|
||||
try {
|
||||
const resultPath = await downloadInstaller(
|
||||
{
|
||||
version: "0.2.0",
|
||||
title: "Scoreko 0.2.0",
|
||||
installer: {
|
||||
name: "Scoreko/setup:0.2.0.exe",
|
||||
downloadUrl: "https://updates.local/Scoreko-setup-0.2.0.exe",
|
||||
size: cachedSize,
|
||||
},
|
||||
},
|
||||
{ tempDirectory, allowInsecureHttp: false },
|
||||
);
|
||||
|
||||
assert.equal(resultPath, installerPath);
|
||||
assert.equal(fs.readFileSync(resultPath, "utf8"), "cached-installer-bytes");
|
||||
} finally {
|
||||
globalThis.fetch = previousFetch;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user