Files
factorio-clusterio/test/lib/zlib_sync.test.js
T
bbassieandClaude Opus 5.5 4d7c1020b0 Use fflate for zlib in the web interface
ModPack and map exchange strings need synchronous inflate and deflate.
In the browser these came from the browserify-zlib polyfill, which
brings pako, assert and util along. The browser build now imports
fflate through a #zlib_sync subpath import, Node.js keeps node:zlib.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 10:18:37 +00:00

26 lines
978 B
JavaScript

/* 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"
);
});
});