Files
archify-vscode-ext/test/schema.test.ts
T
root-at-skic d2f52d43ac 0.3.0: .archify files are YAML and open straight into the diagram
- .archify content is YAML (JSON still accepted); converted to JSON for the renderer
- Archify Diagram custom editor is the default for *.archify; Show Source opens the YAML beside it
- YAML syntax errors and validation problems mapped to YAML lines
- yamlValidation for schema completion with redhat.vscode-yaml
- scripts/to-yaml.mjs converts existing .archify files
2026-09-30 15:21:55 +03:00

45 lines
1.8 KiB
TypeScript

import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import { test } from 'node:test';
import Ajv2020 from 'ajv/dist/2020';
import { parse as parseYaml } from 'yaml';
const root = path.resolve(__dirname, '..', '..');
const schemas = path.join(root, 'schemas');
const fixtures = path.join(root, 'test', 'fixtures');
function validator() {
const ajv = new Ajv2020({ strict: false, allErrors: true });
// Register every schema under its file name, exactly how the relative
// $refs in the bundled copies resolve inside VS Code.
for (const file of fs.readdirSync(schemas)) {
ajv.addSchema(JSON.parse(fs.readFileSync(path.join(schemas, file), 'utf8')), file);
}
return ajv.getSchema('archify.schema.json')!;
}
test('bundled schemas carry no absolute $id', () => {
for (const file of fs.readdirSync(schemas)) {
assert.equal(JSON.parse(fs.readFileSync(path.join(schemas, file), 'utf8')).$id, undefined, file);
}
});
test('the .archify schema accepts every fixture', () => {
const validate = validator();
for (const file of fs.readdirSync(fixtures)) {
const ok = validate(parseYaml(fs.readFileSync(path.join(fixtures, file), 'utf8')));
assert.ok(ok, `${file}: ${JSON.stringify(validate.errors?.slice(0, 3))}`);
}
});
test('the .archify schema applies the schema of the declared type', () => {
const validate = validator();
const sequence = parseYaml(fs.readFileSync(path.join(fixtures, 'cache-miss.archify'), 'utf8'));
// A sequence diagram is not a valid architecture diagram.
assert.equal(validate({ ...sequence, diagram_type: 'architecture' }), false);
assert.equal(validate({ ...sequence, diagram_type: 'poster' }), false);
const { diagram_type: _omitted, ...untyped } = sequence;
assert.equal(validate(untyped), false);
});