import assert from 'node:assert/strict'; import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { test } from 'node:test'; import { readDiagramSource } from '../src/detect'; import { renderDiagram, renderToFile, RuntimeOptions, validate } from '../src/renderer'; const root = path.resolve(__dirname, '..', '..'); const fixtures = path.join(root, 'test', 'fixtures'); const workDir = fs.mkdtempSync(path.join(os.tmpdir(), 'archify-ext-test-')); function runtime(extra: Partial = {}): RuntimeOptions { return { cliPath: path.join(root, 'vendor', 'archify', 'bin', 'archify.mjs'), nodePath: process.execPath, runAsNode: false, workDir, ...extra, }; } function load(name: string) { const text = fs.readFileSync(path.join(fixtures, name), 'utf8'); const source = readDiagramSource(text, name); assert.ok(source, `${name} is a diagram source`); return source; } for (const name of fs.readdirSync(fixtures).filter((file) => !file.startsWith('mco-'))) { test(`renders ${name}`, async () => { const result = await renderDiagram(runtime(), load(name), 'strict'); assert.equal(result.error, undefined); assert.ok(result.ok); assert.match(result.html ?? '', /