Files
factorio-clusterio/test/lib/zip_ops.js
T
Hornwitser aeac7eedec zip_ops: Deduce root folder from first zip entry (#739)
Some mods, for example cubium, includes bogus folders like __MACOSX in
addition to the root folder where everything is located.  This only
works by chance as Factorio will check for the folder of the first
entry in the zip file and use that.

Match Factorio's logic in findRoot so that these mods work with
Clusterio.
2025-03-21 23:00:30 +00:00

47 lines
1.1 KiB
JavaScript

"use strict";
const assert = require("assert").strict;
const JSZip = require("jszip");
const { findRoot } = require("@clusterio/lib");
describe("lib/factorio", function() {
describe("findRoot()", function() {
it("should find the root of a zip", function() {
let zip = new JSZip();
zip.file("root/foo.txt", "");
zip.file("root/bar.txt", "");
assert.equal(findRoot(zip), "root");
});
it("should throw if the first file is at the root of the zip", function() {
let zip = new JSZip();
zip.file("bar.txt", "");
zip.file("root/foo.txt", "");
assert.throws(
() => findRoot(zip),
new Error("Zip contains file 'bar.txt' in root dir")
);
});
it("should return directory of first file if there are multiple root dirs", function() {
let zip = new JSZip();
zip.file("root-1/foo.txt", "");
zip.file("root-2/bar.txt", "");
assert.equal(findRoot(zip), "root-1");
});
it("should throw if given an empty zip file", function() {
let zip = new JSZip();
assert.throws(
() => findRoot(zip),
new Error("Empty zip file")
);
});
});
});