refactor: strengthen test infrastructure and consolidate shared logic#1427
Merged
refactor: strengthen test infrastructure and consolidate shared logic#1427
Conversation
- Add tests/helpers/schemas.ts with common GraphQL schema constants shared across all five validator spec files (PrimitiveInput, ArrayInput, etc.) - Add tests/helpers/plugin.ts with a runPlugin() wrapper to reduce buildSchema + plugin() boilerplate in tests - Add expectTypeScriptToCompile checks to myzod, valibot, and yup primitive tests (myzod/valibot had zero compile checks; this adds a baseline) - Extract src/zod/shared.ts: 22 module-level functions (≈250 lines) that were 100% identical in zod/index.ts and zodv4/index.ts; both files now import from the shared module (similarity-ts reported 100% match on generateFieldTypeZodSchema and defaultValueExpression among others) - Add src/lazy.ts with buildMaybeLazy() — the core isComplex check that drives lazy-reference wrapping was duplicated across all five validators; each now passes its own library prefix as a callback - Add src/scalar.ts with buildScalarSchema() — the scalarSchemas → typeMap → defaultScalarTypeSchema → fallback pattern was ~84% similar across all five validators; yup's .defined() wrapping is handled via the wrapCustom option All 357 tests pass unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…peScript 6 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
aae70f0 to
5a53a42
Compare
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.
Summary
tests/helpers/schemas.tsto eliminate repetition across all 5 spec filestests/helpers/plugin.tswrappingbuildSchema+plugin()into a singlerunPlugin()helperexpectTypeScriptToCompilecoverage totests/yup.spec.ts,tests/myzod.spec.ts, andtests/valibot.spec.tsfor the primary non-null input test casesrc/zod/index.tsandsrc/zodv4/index.tsinto a newsrc/zod/shared.tssrc/lazy.tswith genericbuildMaybeLazyused by all 5 validators (eliminates per-librarymaybeLazyduplication)src/scalar.tswith genericbuildScalarSchemaused by all 5 validators (eliminates per-library*4Scalarduplication)Test plan
pnpm test)pnpm typecheck)🤖 Generated with Claude Code