Skip to content

refactor: strengthen test infrastructure and consolidate shared logic#1427

Merged
Code-Hex merged 4 commits intomainfrom
claude/magical-ride-5529f6
Apr 25, 2026
Merged

refactor: strengthen test infrastructure and consolidate shared logic#1427
Code-Hex merged 4 commits intomainfrom
claude/magical-ride-5529f6

Conversation

@Code-Hex
Copy link
Copy Markdown
Owner

Summary

  • Extracted 8 shared GraphQL schema string constants into tests/helpers/schemas.ts to eliminate repetition across all 5 spec files
  • Created tests/helpers/plugin.ts wrapping buildSchema + plugin() into a single runPlugin() helper
  • Added expectTypeScriptToCompile coverage to tests/yup.spec.ts, tests/myzod.spec.ts, and tests/valibot.spec.ts for the primary non-null input test case
  • Extracted 22 functions that were 100% identical between src/zod/index.ts and src/zodv4/index.ts into a new src/zod/shared.ts
  • Created src/lazy.ts with generic buildMaybeLazy used by all 5 validators (eliminates per-library maybeLazy duplication)
  • Created src/scalar.ts with generic buildScalarSchema used by all 5 validators (eliminates per-library *4Scalar duplication)

Test plan

  • All 357 existing tests pass (pnpm test)
  • TypeScript type checking passes (pnpm typecheck)
  • No snapshot changes — generated output is identical to before refactoring

🤖 Generated with Claude Code

Code-Hex and others added 3 commits April 25, 2026 23:00
- 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>
@Code-Hex Code-Hex force-pushed the claude/magical-ride-5529f6 branch from aae70f0 to 5a53a42 Compare April 25, 2026 14:14
@Code-Hex Code-Hex merged commit 635394e into main Apr 25, 2026
@Code-Hex Code-Hex deleted the claude/magical-ride-5529f6 branch April 25, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant