Files
factorio-clusterio/test/integration/patch.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.7 KiB
JavaScript

import assert from "node:assert/strict";
import fs from "node:fs/promises";
import JSZip from "jszip";
import path from "node:path";
import { patch, SaveModule } from "@clusterio/host/dist/node/src/patch.js";
import * as lib from "@clusterio/lib";
import { slowTest } from "./index.js";
// The server integration test is required to run before this one
import "./server.js";
describe("Integration of lib/factorio/patch", function() {
describe("patch()", function() {
let savePath = path.join("temp", "test", "integration", "saves", "test.zip");
it("should patch a freeplay game", async function() {
slowTest(this);
let testModule = new SaveModule(new lib.ModuleInfo("test", "1.0.0"));
let subdirModule = new SaveModule(new lib.ModuleInfo("subdir", "1.0.0"));
await testModule.loadFiles("test/file/modules/test");
await subdirModule.loadFiles("test/file/modules/subdir");
await patch(savePath, [testModule, subdirModule]);
let zip = await JSZip.loadAsync(await fs.readFile(savePath));
assert.equal(await zip.file("test/modules/test/test.lua").async("string"), "-- test\n");
assert.equal(await zip.file("test/modules/subdir/dir/test.lua").async("string"), "-- test\n");
assert.equal(
await zip.file("test/locale/en/test.cfg").async("string"),
"module-test=A Test\n"
);
assert.equal(
await zip.file("test/locale/en/test-locale.cfg").async("string"),
"module-test-locale=Test Locale\n"
);
});
it("should remove old modules in a save", async function() {
slowTest(this);
await patch(savePath, []);
let zip = await JSZip.loadAsync(await fs.readFile(savePath));
assert.equal(zip.file("test/modules/test/test.lua"), null);
});
});
});