Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/shy-shoes-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@traversable/zod-test": patch
---

fix(zod-test): fixes type-level bug where `SeedGenerator` was returning type `fc.Arbitrary<unknown>` (#557)
2 changes: 2 additions & 0 deletions packages/zod-test/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export * as Seed from './generator-seed.js'

export { fuzz } from './fuzz.js'
export type { Config } from './generator-options.js'
export type * as Bounds from './generator-bounds.js'
export {
SeedMap,
SchemaGenerator,
SeedGenerator,
SeedInvalidDataGenerator,
Expand Down
6 changes: 3 additions & 3 deletions packages/zod-test/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const UnaryMap = {
map: (tie) => fc.tuple(fc.constant(byTag.map), fc.tuple(tie('*'), tie('*'))),
pipe: (tie) => fc.tuple(fc.constant(byTag.pipe), fc.tuple(tie('*'), tie('*'))),
transform: (tie) => fc.tuple(fc.constant(byTag.transform), tie('*')),
promise: () => PromiseSchemaIsUnsupported('SeedMap'),
promise: (tie) => fc.tuple(fc.constant(byTag.promise), tie('*')),
} satisfies { [K in keyof Seed.UnaryMap<never>]: SeedBuilder<K> }

const TerminalSeeds = fn.map(Object_keys(TerminalMap), (tag) => byTag[tag])
Expand Down Expand Up @@ -657,7 +657,7 @@ const seedsThatPreventGeneratingInvalidData = [
* const ZodSchema = zxTest.seedToSchema(seed)
* const dataset = fc.sample(zxTest.seedToValidData(seed), 5)
*
* const results = dataset.map((pt) => ZodSchema.safeParse(pt).success)
* const results = dataset.map((data) => ZodSchema.safeParse(data).success)
*
* console.log(results) // => [true, true, true, true, true]
*/
Expand Down Expand Up @@ -692,7 +692,7 @@ export const SeedValidDataGenerator = SeedGenerator({ exclude: seedsThatPreventG
* const ZodSchema = zxTest.seedToSchema(seed)
* const dataset = fc.sample(zxTest.seedToInvalidData(seed), 5)
*
* const results = dataset.map((pt) => ZodSchema.safeParse(pt).success)
* const results = dataset.map((data) => ZodSchema.safeParse(data).success)
*
* console.log(results) // => [false, false, false, false, false]
*/
Expand Down
49 changes: 49 additions & 0 deletions packages/zod-test/test/generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,52 @@ vi.describe('〖️⛳️〗‹‹‹ ❲@traversable/zod-test❳', () => {
`)
})
})

vi.describe('〖️⛳️〗‹‹‹ ❲@traversable/zod-test❳: type-level tests', () => {
vi.test('〖️⛳️〗› ❲zxTest.SeedGenerator❳: Builder["*"] return type', () => {
vi.expectTypeOf(zxTest.SeedGenerator()['*']).toEqualTypeOf<
fc.Arbitrary<
| [10]
| [15]
| [20]
| [25]
| [30]
| [35]
| [40]
| [45]
| [50]
| [55]
| [60]
| [100, zxTest.Bounds.int]
| [150, zxTest.Bounds.bigint]
| [200, zxTest.Bounds.number]
| [250, zxTest.Bounds.string]
| [500, any]
| [550, string | number | bigint | boolean]
| zxTest.Seed.Seed.TemplateLiteral
| [1000, unknown, zxTest.Bounds.array]
| [1500, unknown]
| [2000, unknown]
| [2500, unknown]
| [3000, unknown]
| [3500, unknown]
| [4000, unknown]
| [5000, unknown]
| [5500, unknown]
| [5600, unknown]
| [6000, [[7500, [string, unknown][]], [7500, [string, unknown][]]]]
| [6500, [unknown, unknown]]
| [7000, unknown]
| [7500, [string, unknown][]]
| [8000, unknown[]]
| [8500, unknown[]]
| [9000, [unknown, unknown]]
| [9500, unknown]
| [10000, unknown]
| [10500, () => unknown]
| [100000, unknown]
>
>()
})
})

Loading