Skip to content

Commit ff0fdec

Browse files
committed
Show validation errors if test instances
1 parent a7cb73f commit ff0fdec

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

scripts/schema-test-coverage.mjs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ addMediaTypePlugin("application/schema+yaml", {
2727
fileMatcher: (path) => path.endsWith(".yaml")
2828
});
2929

30-
/** @type (testDirectory: string) => AsyncGenerator<Json> */
30+
/** @type (testDirectory: string) => AsyncGenerator<[string,Json]> */
3131
const tests = async function* (testDirectory) {
3232
for (const file of await readdir(testDirectory, { recursive: true, withFileTypes: true })) {
3333
if (!file.isFile() || !file.name.endsWith(".yaml")) {
@@ -36,18 +36,21 @@ const tests = async function* (testDirectory) {
3636

3737
const testPath = join(file.parentPath, file.name);
3838
const testJson = await readFile(testPath, "utf8");
39-
yield YAML.parse(testJson);
39+
40+
yield [testPath, YAML.parse(testJson)];
4041
}
4142
};
4243

4344
/** @type (testDirectory: string) => Promise<void> */
4445
const runTests = async (testDirectory) => {
45-
for await (const test of tests(testDirectory)) {
46+
for await (const [name, test] of tests(testDirectory)) {
4647
const instance = Instance.fromJs(test);
4748

4849
const result = interpret(compiled, instance, BASIC);
49-
//TODO: now result has errors array if valid is false
50-
// if (!result.valid) console.log(result)
50+
51+
if (!result.valid) {
52+
console.log("Failed:", name, result.errors);
53+
}
5154
}
5255
};
5356

@@ -100,7 +103,7 @@ const allKeywords = keywordLocations(compiled.ast);
100103
const notCovered = allKeywords.filter((location) => !visitedLocations.has(location));
101104
console.log("NOT Covered:", notCovered.length, "of", allKeywords.length,);
102105

103-
const maxNotCovered = 10;
106+
const maxNotCovered = 20;
104107
const firstNotCovered = notCovered.slice(0, maxNotCovered);
105108
if (notCovered.length > maxNotCovered) firstNotCovered.push("...");
106109
console.log(firstNotCovered);

0 commit comments

Comments
 (0)