feat: export portable native road packages
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
"use strict";
|
||||
|
||||
const assert = require("assert/strict");
|
||||
const crypto = require("crypto");
|
||||
const { execFileSync } = require("child_process");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { unzipSync, strFromU8 } = require("fflate");
|
||||
const { compiler } = require("../src");
|
||||
const { exportNativeRoadPackage } = require("../src/export/native-road-package");
|
||||
|
||||
const root = path.resolve(__dirname, "..");
|
||||
for (const areaId of ["fengshu-er-road", "nantaizi-lake-innovation-valley"]) {
|
||||
@@ -23,5 +27,23 @@ for (const areaId of ["fengshu-er-road", "nantaizi-lake-innovation-valley"]) {
|
||||
const { result } = compiler.compileInput(input);
|
||||
assert.equal(result.areaId, areaId);
|
||||
assert.ok(fs.existsSync(path.join(input.outDir, "compiled.json")));
|
||||
const first = exportNativeRoadPackage(input.outDir);
|
||||
const second = exportNativeRoadPackage(input.outDir);
|
||||
assert.equal(crypto.createHash("sha256").update(first.bytes).digest("hex"), crypto.createHash("sha256").update(second.bytes).digest("hex"));
|
||||
const entries = unzipSync(first.bytes);
|
||||
const manifest = JSON.parse(strFromU8(entries["manifest.json"]));
|
||||
assert.equal(manifest.areaId, areaId);
|
||||
assert.equal(manifest.contract, "native-road-package/v1.1");
|
||||
assert.deepEqual(manifest.generator, { name: "road-compiler", version: "0.3.0" });
|
||||
assert.equal("source" in JSON.parse(strFromU8(entries["compiled.json"])), false);
|
||||
assert.equal(Object.keys(entries).some((entry) => entry.includes("override") || entry.endsWith(".osm")), false);
|
||||
assert.equal(Object.keys(entries).length, 18);
|
||||
if (isFengshu) {
|
||||
const inputFile = path.join(outputRoot, "road-compiler-input.json");
|
||||
const archive = path.join(outputRoot, "export.zip");
|
||||
fs.writeFileSync(inputFile, `${JSON.stringify(input)}\n`);
|
||||
execFileSync(process.execPath, [path.join(root, "bin", "road-compiler.js"), "--input", inputFile, "--export-zip", archive]);
|
||||
assert.ok(fs.existsSync(archive));
|
||||
}
|
||||
}
|
||||
console.log("road compiler fixture tests passed");
|
||||
|
||||
Reference in New Issue
Block a user