chore(test): replace is-my-json-valid with ajv - #885
Open
appsir2016-lab wants to merge 1 commit into
Open
appsir2016-lab wants to merge 1 commit into
appsir2016-lab wants to merge 1 commit into
Conversation
Closes fastify#581 Signed-off-by: P & A Dawn works <appsir2016@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces
is-my-json-validin the tests withajv+ajv-formats, the validator the library already depends on, via a small helper intest/utils/validator.js.is-my-json-validis removed fromdevDependencies.Switching validators surfaced three places where the old one silently accepted output that ajv does not. None of them changes library behaviour; the tests now pin what the serializer does today:
format: 'time'is rendered asHH:mm:sswith no timezone (asTimeinlib/serializer.js). RFC 3339 requires a timezone, so ajv-formats rejects it in bothfullandfastmode. The helper registers atimeformat that matches the documented shape.{ type: ['string', 'null'], const: 'baz' }with inputnullserializes tonull. In JSON Schemaconstapplies regardless oftype, so ajv reports this as invalid.test/const.test.jsnow asserts the mismatch explicitly instead of asserting validity.{ nullable: true, const: 'baz' }cannot be compiled by ajv at all ("nullable" cannot be used without "type"), so that test no longer validates the output against the schema.Items 2 and 3 may be worth a separate discussion about whether the serializer should honour
constbeforetype: null. This PR does not change that.is-my-json-validdid not implementconst, which is why these went unnoticed. The old validator also ignored the fast-json-stringify specificformat: 'unsafe'; the helper registers it as always valid to avoid ajv's unknown-format warning.Checks run locally:
npm run test(516 unit tests, 100% coverage, TypeScript tests) andnpm run lint, all passing on Node 26.Checklist
npm run test && npm run benchmark --if-present(benchmark not run: test-only change)Closes #581