mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 08:03:13 +09:00
Merge pull request #1236 from bbassie/chore/web-bundle-zip-zlib
Keep yauzl, browserify-zlib and assert out of the web interface
This commit is contained in:
16 files changed
+146
-74
No files matched your search
@@ -6,7 +6,8 @@ import stream from "node:stream";
|
||||
// Capture native fetch before any potential mocks are applied
|
||||
const nativeFetch = global.fetch;
|
||||
|
||||
import { ModStore, ModInfo, ModVersionEquality, zipOutputStream } from "@clusterio/lib";
|
||||
import { ModStore, ModInfo, ModVersionEquality, zipOutputStream, hashFile } from "@clusterio/lib";
|
||||
import * as libBuildMod from "@clusterio/lib/build_mod.js";
|
||||
import { externalTest, createZip, createZipBuffer } from "../common.js";
|
||||
import "../setup_logging.js";
|
||||
|
||||
@@ -706,6 +707,38 @@ describe("lib/ModStore", function () {
|
||||
});
|
||||
|
||||
// === Instance Methods ===
|
||||
describe("readModInfo (static)", function () {
|
||||
it("should load from a mod zip file", async function () {
|
||||
await libBuildMod.build({
|
||||
build: true,
|
||||
pack: true,
|
||||
sourceDir: path.join("test", "file", "empty_mod"),
|
||||
outputDir: path.join("temp", "test"),
|
||||
});
|
||||
const filePath = path.join("temp", "test", "empty_mod_1.0.0.zip");
|
||||
const hash = await hashFile(filePath);
|
||||
const stat = await fs.stat(filePath);
|
||||
const mod = await ModStore.readModInfo(filePath);
|
||||
assert.deepEqual(
|
||||
mod,
|
||||
ModInfo.fromJSON({
|
||||
name: "empty_mod",
|
||||
version: "1.0.0",
|
||||
title: "An Empty Mod",
|
||||
author: "Me",
|
||||
description: "An empty mod for testing",
|
||||
factorio_version: "1.1",
|
||||
dependencies: [],
|
||||
filename: "empty_mod_1.0.0.zip",
|
||||
size: stat.size,
|
||||
mtime_ms: stat.mtimeMs,
|
||||
updated_at_ms: stat.mtimeMs,
|
||||
sha1: hash,
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Instance Methods", function () {
|
||||
let modStore;
|
||||
let testMod1Name = "test-mod-1";
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import assert from "node:assert/strict";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import * as lib from "@clusterio/lib";
|
||||
import * as libBuildMod from "@clusterio/lib/build_mod.js";
|
||||
import { ModInfo, ModDependency } from "@clusterio/lib";
|
||||
|
||||
import { testMatrix, testRoundTripJsonSerialisable } from "../../common.js";
|
||||
@@ -413,35 +410,6 @@ describe("lib/data/ModInfo", function() {
|
||||
["UltraMod", "SuperLib >= 1.00", "! bad-mod"].map(dep => new ModDependency(dep))
|
||||
);
|
||||
});
|
||||
it("should load from a mod zip file", async function() {
|
||||
await libBuildMod.build({
|
||||
build: true,
|
||||
pack: true,
|
||||
sourceDir: path.join("test", "file", "empty_mod"),
|
||||
outputDir: path.join("temp", "test"),
|
||||
});
|
||||
const filePath = path.join("temp", "test", "empty_mod_1.0.0.zip");
|
||||
const hash = await lib.hashFile(filePath);
|
||||
const stat = await fs.stat(filePath);
|
||||
const mod = await ModInfo.fromModFile(filePath);
|
||||
assert.deepEqual(
|
||||
mod,
|
||||
ModInfo.fromJSON({
|
||||
name: "empty_mod",
|
||||
version: "1.0.0",
|
||||
title: "An Empty Mod",
|
||||
author: "Me",
|
||||
description: "An empty mod for testing",
|
||||
factorio_version: "1.1",
|
||||
dependencies: [],
|
||||
filename: "empty_mod_1.0.0.zip",
|
||||
size: stat.size,
|
||||
mtime_ms: stat.mtimeMs,
|
||||
updated_at_ms: stat.mtimeMs,
|
||||
sha1: hash,
|
||||
})
|
||||
);
|
||||
});
|
||||
describe("checkDependencySatisfaction()", function() {
|
||||
it("should return undefined when satisfied", function() {
|
||||
const mod = ModInfo.fromJSON({ dependencies: ["! a", "b = 1.0.0", "? c = 2.0.0"] });
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/* eslint-disable node/no-sync */
|
||||
import assert from "node:assert/strict";
|
||||
import zlib from "node:zlib";
|
||||
|
||||
import * as browserZlib from "../../packages/lib/src/zlib_sync.browser.ts";
|
||||
|
||||
describe("lib/zlib_sync.browser", function() {
|
||||
const text = JSON.stringify({ name: "pack", mods: [{ name: "base", version: "2.0.0" }] });
|
||||
|
||||
it("should inflate data deflated by node:zlib", function() {
|
||||
const inflated = browserZlib.inflateSync(zlib.deflateSync(text));
|
||||
assert.equal(Buffer.from(inflated).toString(), text);
|
||||
});
|
||||
it("should deflate data node:zlib can inflate", function() {
|
||||
assert.equal(zlib.inflateSync(browserZlib.deflateSync(text)).toString(), text);
|
||||
const bytes = Buffer.from(text);
|
||||
assert.equal(zlib.inflateSync(browserZlib.deflateSync(bytes)).toString(), text);
|
||||
});
|
||||
it("should throw with a Z_ code on invalid data", function() {
|
||||
assert.throws(
|
||||
() => browserZlib.inflateSync(Buffer.from("not zlib data")),
|
||||
err => err.code === "Z_DATA_ERROR"
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user