test: add unit tests for low-coverage utility modules
## Summary
Adds **108 new unit tests** (5 new suites) that target the package source files with the lowest prior test coverage. The existing test suite in `tests/jest` drives almost everything through full server-action integration tests (`index.test.tsx`, `client.test.tsx`, `openapi.test.tsx`), which left the smaller utility modules effectively unexercised as standalone units.
New test files (all under `tests/jest/__tests__/`):
- `unit-zsa-utils.tsx` — 36 tests for `packages/zsa/src/utils.ts`: `instanceofZodTypeKind`, `unwrapZodType` (optional / default / lazy / effects / preprocess), `instanceofZodTypeObject/Array/Boolean`, `isKeyAnArrayInZodSchema`, `isKeyABooleanInZodSchema`, `formDataToJson` (scalar, array, promoted-array, boolean coercion), `addToNullishArray`, `mergeArraysAndRemoveDuplicates`, `instanceofZodTypeLikeVoid`, `canDataBeUndefinedForSchema`.
- `unit-zsa-errors.tsx` — 6 tests for `packages/zsa/src/errors.ts` `ZSAError` (default code, custom code, string-data messages, copying fields from a wrapped `Error`, input/output parse errors, opaque non-string data).
- `unit-zsa-openapi-utils.tsx` — 24 tests for `packages/zsa-openapi/src/utils.ts`: `acceptsRequestBody`, `normalizePath`, `getPathParameters`, `preparePathForMatching`, `getPathRegExp` (including case-insensitivity and non-match cases), and all 17 branches of `getErrorStatusFromZSAError`.
- `unit-zsa-openapi-zod.tsx` — 22 tests for `packages/zsa-openapi/src/zod.ts`: `instanceofZodType`, `instanceofZodTypeOptional`, `instanceofZodTypeLikeString` (strings, enums, native enums, literals, preprocess effects, unions, intersections), `instanceofZodTypeCoercible`, `zodSupportsCoerce`.
- `unit-zsa-react-utils.tsx` — 20 tests for the four small `packages/zsa-react/src` helper files: `mergePossibleObjects`, `getRetryDelay` (no-config, exhausted, numeric delay, functional delay), `evaluateOptimisticInput` (static value, filled old, empty old), `calculateResultFromState` (idle, pending non-optimistic, persistDataWhilePending, persistErrorWhilePending, optimistic pending, success, error), `getEmptyResult`, `getEmptyOldResult`.
Each test imports the helper **directly from the package `src/`** so coverage tooling observes the source files rather than the already-bundled `dist/` output.
### Why the `tests/jest/tsconfig.json` change?
The only non-test change is bumping `tests/jest/tsconfig.json`'s `target` from `es5` to `es2017`. Previously the tests tsconfig only ever saw code through the published `dist/` types, so the `es5` target was harmless. Importing `packages/zsa/src/utils.ts` directly pulls its `[...new Set(temp)]` into the `tsc --noEmit` program, which requires `target >= es2015`. `es2017` aligns with the Node >= 18 engine the repo already targets and is only consumed by `tsc --noEmit`; runtime transpilation still comes from `next/jest`'s SWC pipeline, so behavior is unchanged.
### Test results
All jest suites pass locally (`npx jest` in `tests/jest`):
```
Test Suites: 8 passed, 8 total
Tests: 238 passed, 238 total
```
`npx turbo typecheck` also passes across all packages.
## Review & Testing Checklist for Human
- [ ] Confirm the `tests/jest/tsconfig.json` target change (`es5` → `es2017`) is acceptable. It only affects `tsc --noEmit`; runtime goes through `next/jest`'s SWC.
- [ ] Spot-check at least one new test file (e.g. `unit-zsa-utils.tsx`) and confirm the tests reflect intended behavior of the helper rather than just locking in current behavior.
- [ ] Verify CI is green (build, jest, playwright, typecheck).
### Notes
- No source code in `packages/*/src` was modified — only new test files and a tsconfig target bump.
- I considered importing helpers via the published package names (`zsa`, `zsa-react`, ...) but most of the targeted helpers (`mergePossibleObjects`, `getRetryDelay`, `calculateResultFromState`, `instanceofZodTypeLikeString`, etc.) aren't re-exported from the packages' `index.ts`, so direct `src/` imports are required to unit-test them.
Link to Devin session: https://localhost:3000/sessions/a5561facf4df450e91071895cb777819
Requested by: @IdoPesok
合并状态:未合并 3 条评论