feat: migrate workbench to React
This commit is contained in:
@@ -1,49 +1,61 @@
|
||||
"use strict";
|
||||
'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 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"]) {
|
||||
const isFengshu = areaId === "fengshu-er-road";
|
||||
const outputRoot = path.join(root, "outputs", areaId);
|
||||
const root = path.resolve(__dirname, '..');
|
||||
for (const areaId of ['fengshu-er-road', 'nantaizi-lake-innovation-valley']) {
|
||||
const isFengshu = areaId === 'fengshu-er-road';
|
||||
const outputRoot = path.join(root, 'outputs', areaId);
|
||||
const input = {
|
||||
areaId,
|
||||
osmFile: path.join(root, "inputs", "osm", isFengshu ? "枫树二路.osm" : "南台子湖创新谷OSM.osm"),
|
||||
outDir: path.join(outputRoot, "native-road"),
|
||||
stagingDir: path.join(outputRoot, "_pipeline"),
|
||||
overridesFile: path.join(outputRoot, "native-road-overrides.json"),
|
||||
trafficSignalsFile: path.join(outputRoot, "native-traffic-signals.json"),
|
||||
comparisonDir: path.join(outputRoot, "osm2streets_web_out"),
|
||||
osmFile: path.join(root, 'inputs', 'osm', isFengshu ? '枫树二路.osm' : '南台子湖创新谷OSM.osm'),
|
||||
outDir: path.join(outputRoot, 'native-road'),
|
||||
stagingDir: path.join(outputRoot, '_pipeline'),
|
||||
overridesFile: path.join(outputRoot, 'native-road-overrides.json'),
|
||||
trafficSignalsFile: path.join(outputRoot, 'native-traffic-signals.json'),
|
||||
comparisonDir: path.join(outputRoot, 'osm2streets_web_out'),
|
||||
options: { edgeLines: false, junctionTemplates: { enabled: false, references: [] } },
|
||||
};
|
||||
assert.ok(fs.existsSync(path.join(root, "test", "baseline", `${areaId}.json`)));
|
||||
assert.ok(fs.existsSync(path.join(root, 'test', 'baseline', `${areaId}.json`)));
|
||||
const { result } = compiler.compileInput(input);
|
||||
assert.equal(result.areaId, areaId);
|
||||
assert.ok(fs.existsSync(path.join(input.outDir, "compiled.json")));
|
||||
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"));
|
||||
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"]));
|
||||
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(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");
|
||||
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]);
|
||||
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");
|
||||
console.log('road compiler fixture tests passed');
|
||||
|
||||
Reference in New Issue
Block a user