Build and publish Eldorado documentation / build (pull_request) Successful in 49s
36 lines
2.3 KiB
JavaScript
36 lines
2.3 KiB
JavaScript
import {test} from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {readFileSync, writeFileSync, mkdtempSync, rmSync, mkdirSync} from 'node:fs';
|
|
import {execFileSync} from 'node:child_process';
|
|
import {roadmapViewer} from './roadmap-viewer.mjs';
|
|
|
|
for (const name of ['strategy-roadmap', 'strategy-roadmap-adoption', 'strategy-roadmap-loop']) for (const suffix of ['', '-mobile']) test(`${name}${suffix} retains graph and passes final composition`, () => {
|
|
mkdirSync('.cache', {recursive:true});
|
|
const dir = mkdtempSync('.cache/roadmap-test-');
|
|
try {
|
|
const source = `diagrams/${name}${suffix}.workflow.json`;
|
|
const spec = JSON.parse(readFileSync(source, 'utf8'));
|
|
const output = `${dir}/index.html`;
|
|
execFileSync(process.execPath, ['vendor/archify/renderers/workflow/render-workflow.mjs', source, output], {env:{...process.env, ARCHIFY_UPDATE_CHECK_DISABLED:'1'}});
|
|
const native = readFileSync(output, 'utf8');
|
|
const styled = roadmapViewer(native, spec);
|
|
const graph = html => [...html.matchAll(/<path\b[^>]*data-edge-id="[^"]+"[^>]*>/g)].map(m => m[0]);
|
|
assert.equal(graph(native).length, spec.edges.length);
|
|
assert.deepEqual(graph(styled), graph(native), 'native paths must not be rewritten');
|
|
for (const node of spec.nodes) assert(styled.includes(`data-node-id="${node.id}"`));
|
|
assert.equal((styled.match(/<text data-node-label=/g) || []).length, 0, 'single-line preview replaced');
|
|
assert(styled.includes('eldorado-roadmap-typography'));
|
|
writeFileSync(output, styled);
|
|
const checked = JSON.parse(execFileSync(process.execPath, ['vendor/archify/bin/archify.mjs','check',output,'--json'], {encoding:'utf8', env:{...process.env, ARCHIFY_UPDATE_CHECK_DISABLED:'1'}}));
|
|
assert(checked.ok);
|
|
assert.equal(checked.composition.status, 'pass');
|
|
assert.equal(checked.composition.metrics.properCrossings, 0);
|
|
assert.equal(checked.composition.metrics.labelCanvasOverflowIssues, 0);
|
|
assert.throws(() => roadmapViewer('', spec), /drift/);
|
|
const oversized = structuredClone(spec);
|
|
oversized.nodes[0].sublabel = 'Too much copy '.repeat(20);
|
|
assert.throws(() => roadmapViewer(native, oversized), /capacity/);
|
|
assert.throws(() => roadmapViewer(native, {...spec,diagram_type:'architecture'}), /contract drift/);
|
|
} finally {rmSync(dir, {recursive:true, force:true});}
|
|
});
|