mirror of
https://github.com/Pandipipas/scoreko-electron-dev.git
synced 2026-06-06 05:32:06 +00:00
Refactor NodeCG runtime preparation and update handling
- Updated paths and configurations in doctor.mjs and prepare-nodecg-runtime.mjs to use new build-config.mjs imports. - Enhanced runtime installation checks and permissions validation. - Introduced new update configuration management in update-config.ts, including loading and validating update settings. - Implemented update service for managing update checks and downloads in update-service.ts. - Replaced update-utils.ts with update-schema.ts for better structure and clarity in update handling. - Added comprehensive tests for update download and settings management. - Ensured secure handling of download URLs and improved error handling in update processes.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
|
||||
import { downloadInstaller } from "../main/updates/update-download";
|
||||
|
||||
test("downloadInstaller writes into the update temp directory and removes staging files", async () => {
|
||||
const previousFetch = globalThis.fetch;
|
||||
const tempDirectory = fs.mkdtempSync(path.join(os.tmpdir(), "scoreko-update-download-"));
|
||||
|
||||
globalThis.fetch = async () => new Response("installer-bytes");
|
||||
|
||||
try {
|
||||
const installerPath = 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",
|
||||
},
|
||||
},
|
||||
{ tempDirectory, allowInsecureHttp: false },
|
||||
);
|
||||
|
||||
const downloadDirectory = path.join(tempDirectory, "scoreko-updates");
|
||||
assert.equal(installerPath, path.join(downloadDirectory, "Scoreko_setup_0.2.0.exe"));
|
||||
assert.equal(fs.readFileSync(installerPath, "utf8"), "installer-bytes");
|
||||
assert.deepEqual(
|
||||
fs.readdirSync(downloadDirectory).filter((entry) => entry.endsWith(".download")),
|
||||
[],
|
||||
);
|
||||
} finally {
|
||||
globalThis.fetch = previousFetch;
|
||||
}
|
||||
});
|
||||
|
||||
test("downloadInstaller rejects insecure production download URLs", async () => {
|
||||
const tempDirectory = fs.mkdtempSync(path.join(os.tmpdir(), "scoreko-update-download-"));
|
||||
|
||||
await assert.rejects(
|
||||
() =>
|
||||
downloadInstaller(
|
||||
{
|
||||
version: "0.2.0",
|
||||
title: "Scoreko 0.2.0",
|
||||
installer: {
|
||||
name: "Scoreko-setup-0.2.0.exe",
|
||||
downloadUrl: "http://updates.local/Scoreko-setup-0.2.0.exe",
|
||||
},
|
||||
},
|
||||
{ tempDirectory, allowInsecureHttp: false },
|
||||
),
|
||||
/unsupported protocol/,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user