Files
factorio-clusterio/test/lib/zip_ops.js
T
Hornwitser 5dcaca4d0b Migrate to ECMAScript Modules
Migrate the usage of CommonJS specific code and imports to ESM.  Roughly
summarised this:
- Changes all require() calls to import statement or expressions.
- Changes usage of module.exports to export statements.
- Replaces require.resolve with import.meta.resolve.
- Replaces conditional imports with conditional subpath imports.
- Replaces module === require.main with import.meta.main.
- Adds the full filename with extention to all relative imports.
- Changes all usage of __dirname and __filename to their import.meta
  equivalents.
- Sets "type": "module" in package.json files.
- Removes usage of "use strict".
- Adds .ts an an alias of .js for the webpack build.

Due to differences in how require and import resolves files the plugin
entrypoints will have to include the filename and extension after this
migration in order to work.
2026-09-11 22:43:57 +02:00

46 lines
1.1 KiB
JavaScript

import assert from "node:assert/strict";
import JSZip from "jszip";
import { findRoot } from "@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")
);
});
});
});