Files
FreeCADWasmDev/web/tools/test-fast-public-assets.ts
wangdequan 9a7c4f0335 Save FreeCAD Web workspace sources and user validation evidence
IFC native binding remains incomplete; preserve accurate test results.
2026-09-15 22:01:58 +08:00

41 lines
2.0 KiB
TypeScript

import assert from "node:assert/strict";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { syncPublicAssets } from "./fast-public-assets.ts";
const root = fs.mkdtempSync(path.join(os.tmpdir(), "freecad-public-sync-"));
try {
const source = path.join(root, "public");
const output = path.join(root, "dist");
fs.mkdirSync(path.join(source, "kernel"), { recursive: true });
const asset = path.join(source, "kernel", "module.wasm");
fs.writeFileSync(asset, "first wasm");
syncPublicAssets(source, output);
const destination = path.join(output, "kernel", "module.wasm");
assert.equal(fs.readFileSync(destination, "utf8"), "first wasm");
const inode = fs.statSync(destination).ino;
const modified = fs.statSync(destination).mtimeMs;
fs.writeFileSync(path.join(output, "stale-bundle.js"), "old bundle");
fs.writeFileSync(path.join(output, "kernel", "obsolete.wasm"), "old module");
syncPublicAssets(source, output);
assert.equal(fs.statSync(destination).ino, inode);
assert.equal(fs.statSync(destination).mtimeMs, modified);
assert.equal(fs.existsSync(path.join(output, "stale-bundle.js")), false);
assert.equal(fs.existsSync(path.join(output, "kernel", "obsolete.wasm")), false);
fs.writeFileSync(asset, "other wasm");
const withinSameSecond = Math.floor(modified / 1000) + 0.123456;
fs.utimesSync(asset, withinSameSecond, withinSameSecond);
syncPublicAssets(source, output);
assert.equal(fs.readFileSync(destination, "utf8"), "other wasm");
fs.writeFileSync(asset, "new wasm with changes");
syncPublicAssets(source, output);
assert.equal(fs.readFileSync(destination, "utf8"), "new wasm with changes");
assert.throws(() => syncPublicAssets(source, root), /disjoint/);
fs.symlinkSync(source, path.join(root, "linked"));
assert.throws(() => syncPublicAssets(source, path.join(root, "linked")), /symlink/);
console.log("PASS: incremental asset reuse, replacement, stale cleanup and path guards");
} finally {
fs.rmSync(root, { recursive: true, force: true });
}