Files
factorio-clusterio/test/integration/patch.js
T
Hornwitser 6af25e085c Move Factorio server implementation to host
Move Factorio related code in lib that's only used by the host into the
host package.
2023-07-28 16:03:29 +02:00

48 lines
1.4 KiB
JavaScript

"use strict";
const assert = require("assert").strict;
const fs = require("fs-extra");
const JSZip = require("jszip");
const path = require("path");
const { patch } = require("@clusterio/host/src/patch");
const { slowTest } = require("./index");
// The server integration test is required to run before this one
require("./server");
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);
await patch(savePath, [{
name: "test",
version: "1.0.0",
dependencies: {},
path: "test/file/modules/test",
load: [],
require: [],
}, {
name: "subdir",
version: "1.0.0",
dependencies: {},
path: "test/file/modules/subdir",
load: [],
require: [],
}]);
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");
});
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);
});
});
});