Skip to content

How to measure the test coverage of a schema? #70

Answered by jdesrosiers
ralfhandl asked this question in Q&A
Discussion options

You must be logged in to vote

There's not a good way to determine keywords that passed validation, but here's a hack I came up with. You can run it as a script that takes two arguments: a path to a schema and a path to a directory of JSON instances. Example: node coverage.js subject.schema.json test.

import { readdir, readFile } from "node:fs/promises";
import { join } from "node:path";
import { argv } from "node:process";
import "@hyperjump/json-schema/draft-2020-12";
import { compile, getSchema, interpret, Validation } from "@hyperjump/json-schema/experimental";
import * as Instance from "@hyperjump/json-schema/instance/experimental";

/**
 * @import { AST } from "@hyperjump/json-schema/experimental"
 * @import { Js…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
4 replies
@jdesrosiers
Comment options

Answer selected by ralfhandl
@ralfhandl
Comment options

@ralfhandl
Comment options

@jdesrosiers
Comment options

Comment options

You must be logged in to vote
3 replies
@ralfhandl
Comment options

@jdesrosiers
Comment options

@ralfhandl
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants