Add remaining tests

This commit is contained in:
Cooldude2606 committed 2026-01-24 17:58:36 +00:00
1 parent 6f68cf74a7
commit bbf5df6d01
2 files changed
+61 -9

No files matched your search

+21 -9
View File
@@ -51,8 +51,16 @@ describe("FactorioVersions", function() {
const versions = await fetchFactorioVersions();
assert.deepEqual(versions, [
{ stable: false, version: "2.0.73", downloadUrl: "https://factorio.com/download/archive/2.0.73" },
{ stable: true, version: "2.0.72", downloadUrl: "https://factorio.com/download/archive/2.0.72" },
{
stable: false,
version: "2.0.73",
headlessUrl: "www.factorio.com/get-download/2.0.73/headless/linux64",
},
{
stable: true,
version: "2.0.72",
headlessUrl: "www.factorio.com/get-download/2.0.72/headless/linux64",
},
]);
});
it("deduplicates versions by last occurrence", async function() {
@@ -79,7 +87,11 @@ describe("FactorioVersions", function() {
const versions = await fetchFactorioVersions();
assert.deepEqual(versions, [
{ stable: true, version: "2.0.73", downloadUrl: "https://factorio.com/download/archive/2.0.73" },
{
stable: true,
version: "2.0.73",
headlessUrl: "www.factorio.com/get-download/2.0.73/headless/linux64",
},
]);
});
it("thorws on HTTP error status", async function() {
@@ -105,18 +117,18 @@ describe("FactorioVersions", function() {
mockFetch(await readFile("test/file/html/factorio-download-archive.html"));
const versions = await fetchFactorioVersions();
assert.equal(versions.length, 111);
assert.equal(versions.filter(v => v.stable).length, 53);
assert.equal(versions.filter(v => !v.stable).length, 58);
assert.equal(versions.length, 105);
assert.equal(versions.filter(v => v.stable).length, 48);
assert.equal(versions.filter(v => !v.stable).length, 57);
});
it("parses versions from live api", async function() {
slowTest(this);
global.fetch = originalFetch;
const versions = await fetchFactorioVersions();
assert.ok(versions.length >= 111);
assert.ok(versions.filter(v => v.stable).length >= 53);
assert.ok(versions.filter(v => !v.stable).length >= 58);
assert.ok(versions.length >= 105);
assert.ok(versions.filter(v => v.stable).length >= 48);
assert.ok(versions.filter(v => !v.stable).length >= 57);
});
});
});
+40
View File
@@ -34,4 +34,44 @@ describe("messages/controller", function() {
);
});
});
describe("External", function() {
it("runs", async function() {
let callCount = 0;
const versions = [
{ version: "1.2.3", stable: true, headlessUrl: "path/to/download" },
{ version: "1.2.4", stable: false, headlessUrl: "path/to/download" },
];
// Mock the cache to avoid needless fetches
controller.factorioVersions = new lib.ValueCache(async () => {
callCount += 1;
return versions;
});
// First call should result in a fetch
const versions1 = await controlConnection.handleFactorioVersionsRequest(
new lib.FactorioVersionsRequest()
);
assert.deepEqual(versions1, versions);
assert.equal(callCount, 1);
// Second call should not fetch due to default maxAgeMs being greater than 0
const versions2 = await controlConnection.handleFactorioVersionsRequest(
new lib.FactorioVersionsRequest()
);
assert.deepEqual(versions2, versions);
assert.equal(callCount, 1);
// Setting maxAgeMs to 0 should result in a new fetch
const versions3 = await controlConnection.handleFactorioVersionsRequest(
new lib.FactorioVersionsRequest(0)
);
assert.deepEqual(versions3, versions);
assert.equal(callCount, 2);
});
});
});