|
| 1 | +// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +// NOTE: https://github.com/ajv-validator/ajv-formats/issues/85 |
| 5 | +import Ajv from "https://esm.sh/[email protected]"; |
| 6 | +import addFormats from "https://esm.sh/[email protected]"; |
| 7 | + |
| 8 | +import { parse } from "npm:yaml"; |
| 9 | +import schema from "@local/tools/schema/metatype.json" with { type: "json" }; |
| 10 | +import * as path from "@std/path"; |
| 11 | +import { assert } from "@std/assert"; |
| 12 | +import { Meta } from "test-utils/mod.ts"; |
| 13 | + |
| 14 | +const files = [ |
| 15 | + "../metatype.yml", |
| 16 | + "../../examples/metatype.yaml", |
| 17 | + "../../examples/templates/deno/metatype.yaml", |
| 18 | + "../../examples/templates/node/metatype.yaml", |
| 19 | + "../../examples/templates/python/metatype.yaml", |
| 20 | + "../metagen/typegraphs/sample/metatype.yml", |
| 21 | + "../metagen/typegraphs/identities/metatype.yml", |
| 22 | +]; |
| 23 | + |
| 24 | +Meta.test("Configuration schema", () => { |
| 25 | + const ajv = new Ajv(); |
| 26 | + |
| 27 | + addFormats(ajv); |
| 28 | + |
| 29 | + const validate = ajv.compile(schema); |
| 30 | + const scriptDir = import.meta.dirname!; |
| 31 | + |
| 32 | + for (const file of files) { |
| 33 | + const relativePath = path.resolve(scriptDir, file); |
| 34 | + const yaml = Deno.readTextFileSync(relativePath); |
| 35 | + const parsed = parse(yaml); |
| 36 | + const result = validate(parsed); |
| 37 | + |
| 38 | + assert(result, `validation failed for '${file}'`); |
| 39 | + } |
| 40 | +}); |
0 commit comments