mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-11 23:04:52 +09:00
Add remaining tests
This commit is contained in:
2 files changed
+61
-9
No files matched your search
+21
-9
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user