forked from longtao.wu/droboticflow
26 lines
1.2 KiB
JavaScript
26 lines
1.2 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { mkdtempSync, mkdirSync, readFileSync, writeFileSync, existsSync, rmSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { gunzipSync } from "node:zlib";
|
|
import { precompressAssets } from "../../scripts/lib/precompress-assets.mjs";
|
|
|
|
test("final emitted chunks and copied vendor assets have byte-identical gzip siblings", () => {
|
|
const root = mkdtempSync(join(tmpdir(), "static-assets-"));
|
|
try {
|
|
const paths = ["assets/app.js", "assets/style.css", "vendor/player/element.slim.js", "vendor/player/movi.wasm"];
|
|
for (const path of paths) {
|
|
mkdirSync(join(root, path, ".."), { recursive: true });
|
|
writeFileSync(join(root, path), `final transformed bytes: ${path}`);
|
|
}
|
|
writeFileSync(join(root, "video.mp4"), "already encoded");
|
|
precompressAssets(root);
|
|
for (const path of paths)
|
|
assert.deepEqual(gunzipSync(readFileSync(join(root, path + ".gz"))), readFileSync(join(root, path)));
|
|
assert.equal(existsSync(join(root, "video.mp4.gz")), false);
|
|
} finally {
|
|
rmSync(root, { recursive: true, force: true });
|
|
}
|
|
});
|