-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Switch to @hyperjump/json-schema-coverage for schema test coverage #4762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Here's an example of what we'll get for the 3.1 branch.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jdesrosiers Really nice!
Unfortunately we'd need some additions to use it, see comments.
It looks like defining a vocabulary isn't quite working, so this isn't working on the v3.2-dev branch yet. |
It does work with the "old" solution, both for validation pass/fail and for coverage. |
bd3cdf3
to
96f62b8
Compare
I fixed the problem with registering the vocabulary, so this now works for all branches including v3.2. I also rebased to fix the conflict. As far as I know, the only thing missing at this point is adding additional tests to cover the parts the new solution catches that the old one didn't. I'll leave that part to someone else. |
Unfortunately this does not run on Windows machines, it fails with
The previous implementation worked fine on Windows and Ubuntu. Maybe something is missing when resolving relative paths into file URLs, it should actually try to load resource
which it would find. |
I always forget about Windows! I made some fixes and made sure the tests pass with Github actions on windows. I don't have a windows machine to test locally, so let me know if there are any more issues. |
f0c16c7
to
059a4b0
Compare
Works like a charm, and you even got rid of the dependency to |
Since our last update to the JSON Schema test coverage script, I've been working on a more complete solution and it's finally ready to share! I was able to generate istanbul coverage documents with the information collected from the @hyperjump/json-schema EvaluationPlugin we introduced in the last update. That allows us to generate familiar looking reports. I also figured out how to integrate it with Vitest, so it's super easy to use. I even included support for YAML out-of-the-box. See, @hyperjump/json-schema-coverage for more details and examples.
WARNING: Because this does a more thorough job than the current solution, it will no longer report 100% coverage. More tests will need to be added. The biggest difference is that I added branch coverage support. Instead of just checking that the keyword was covered, it now also tracks whether both the true and false result of a keyword are covered.
WARNING: In the current version, we added a hack to ignore
#/$defs/schema
inschema.yaml
because it isn't possible to cover that location if we're testing againstschema-base.yaml
. This new package doesn't have a solution for ignoring things. We could add a test that usesschema.yaml
to cover that location, or look into some way to ignore coverage in the new solution.NOTE: I think the
dev
branch is the right place to make this PR, but please let me know if that's wrong. The PR template saysmain
, but the coverage tests don't exist on that branch.