Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/unit/schema-validation/schema-files.test.ts
6452 views
1
import { expandGlobSync } from "../../../src/core/deno/expand-glob.ts";
2
import { tidyverseFormatError } from "../../../src/core/lib/errors.ts";
3
import { LocalizedError } from "../../../src/core/lib/yaml-schema/types.ts";
4
import { withValidator } from "../../../src/core/lib/yaml-validation/validator-queue.ts";
5
import { WithValidatorFun } from "../../../src/core/lib/yaml-validation/validator-queue.ts";
6
import { unitTest } from "../../test.ts";
7
import { fullInit, readSelfValidatingSchemaTestFile } from "./utils.ts";
8
9
const globOutput = Deno.args.length
10
? expandGlobSync(Deno.args[0])
11
: expandGlobSync(
12
"docs/schema-files/**/*.yml",
13
);
14
15
await fullInit();
16
17
type Res = {
18
yaml: { [key: string]: unknown };
19
yamlValidationErrors: LocalizedError[];
20
};
21
22
for (const { path: fileName } of globOutput) {
23
const input = fileName;
24
25
unitTest(
26
`schema validation of ${input}`,
27
async () => {
28
const { schema, annotation, mappedYaml } =
29
readSelfValidatingSchemaTestFile(input);
30
31
const validate: WithValidatorFun<Res> = async (validator) => {
32
const valResult = await validator.validateParse(
33
mappedYaml,
34
annotation,
35
);
36
return {
37
yaml: annotation.result as { [key: string]: unknown },
38
yamlValidationErrors: valResult.errors,
39
};
40
};
41
42
const validationResult = await withValidator(
43
schema,
44
validate,
45
);
46
47
if (
48
validationResult.yamlValidationErrors.length !== 0
49
) {
50
for (const error of validationResult.yamlValidationErrors) {
51
console.log(tidyverseFormatError(error.niceError));
52
}
53
throw new Error("validation failed");
54
}
55
},
56
);
57
}
58
59