Files
factorio-clusterio/test/integration/patch.js
T
Hornwitser 80bd75ba16 Rework module loading
Change module loading to use a module.json file describing the module
and patch in all files in a directory path passed to the patcher instead
of having to pass the files names and their content.  This allows the
specification of which files should be passed to the event_handler lib
and an easy implementation of loading stand alone modules.
2020-01-04 17:34:16 +01:00

46 lines
1.4 KiB
JavaScript

const assert = require("assert").strict;
const fs = require("fs-extra");
const jszip = require("jszip");
const path = require("path");
const factorio = require("lib/factorio");
// The server integration test is required to run before this one
require("./server")
describe("Integration of lib/factorio/patch", function() {
// Mark that this test depeneds on a test that takes a lot of time.
function slowTest(test) {
if (process.env.FAST_TEST) {
test.skip();
}
}
describe("patch()", function() {
let savePath = path.join("test", "temp", "integration", "saves", "test.zip");
it("should patch a freeplay game", async function() {
slowTest(this);
await factorio.patch(savePath, [{
name: "test",
path: "test/file/modules/test",
load: [],
}, {
name: "subdir",
path: "test/file/modules/subdir",
load: [],
}]);
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 factorio.patch(savePath, []);
let zip = await jszip.loadAsync(await fs.readFile(savePath));
assert.equal(zip.file("test/modules/test/test.lua"), null);
});
});
});