@traversable/schema
    Preparing search index...

    Module @traversable/valibot-test - v0.0.4


    ᯓ𝘁𝗿𝗮𝘃𝗲𝗿𝘀𝗮𝗯𝗹𝗲/𝘃𝗮𝗹𝗶𝗯𝗼𝘁-𝘁𝗲𝘀𝘁


    Testing utility that generates arbitrary, pseudorandom Valibot schemas, powered by fast-check

    NPM Version   TypeScript   License   npm  
    Static Badge   Static Badge   Static Badge  


    @traversable/valibot-test has 2 peer dependencies:

    1. valibot (v1)
    2. fast-check
    $ pnpm add -D @traversable/valibot-test valibot fast-check
    

    Here's an example of importing the library:

    import * as v from 'valibot'
    import { vxTest } from '@traversable/valibot-test'

    // see below for specifc examples

    Use vxTest.seedToSchema to convert a seed generated by vxTest.SeedGenerator into a valibot schema that satisfies the configuration options you specified.

    import { vxTest } from '@traversable/valibot-test'
    import * as fc from 'fast-check'

    const builder = vxTest.SeedGenerator()['*']
    const [mySeed] = fc.sample(builder.object, 1)

    const mySchema = vxTest.seedToSchema(mySeed)
    // ^? const mySchema: v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>

    Use vxTest.seedToValidData to convert a seed generated by vxTest.SeedGenerator into data that satisfies the schema that the seed represents.

    import { vxTest } from '@traversable/valibot-test'
    import * as fc from 'fast-check'

    const builder = vxTest.SeedGenerator()['*']
    const [mySeed] = fc.sample(builder.object, 1)

    const mySchema = vxTest.seedToSchema(mySeed)
    // ^? const mySchema: v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>

    const validData = vxTest.seedToValidData(mySeed)

    mySchema.parse(validData) // will never throw

    Use vxTest.seedToInvalidData to convert a seed generated by vxTest.SeedGenerator into data that does not satisfy the schema that the seed represents.

    import { vxTest } from '@traversable/valibot-test'
    import * as fc from 'fast-check'

    const builder = vxTest.SeedGenerator()['*']
    const [mySeed] = fc.sample(builder.object, 1)

    const mySchema = vxTest.seedToSchema(mySeed)
    // ^? const mySchema: v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>

    const invalidData = vxTest.seedToValidData(mySeed)

    mySchema.parse(invalidData) // should always throw

    Generates a configurable, pseudo-random "seed builder".

    import { vxTest } from '@traversable/valibot-test'
    import * as fc from 'fast-check'

    const builder = vxTest.SeedGenerator({
    include: ["boolean", "string", "object"],
    // 𐙘 use `include` to only include certain schema types
    exclude: ["boolean", "any"],
    // 𐙘 use `exclude` to exclude certain schema types altogether (overrides `include`)
    minDepth: 1,
    // 𐙘 use `minDepth` to control the schema's minimum depth
    // **NOTE:** schemas can get very large!
    // using in your CI/CD pipeline is _not_ recommended
    object: { maxKeys: 5 },
    // 𐙘 specific arbitraries are configurable by name
    })

    // included schemas are present as properties on your generator...
    builder.string
    builder.object

    // ...excluded schemas are not present...
    builder.boolean // 🚫 TypeError

    // ...a special wildcard `"*"` property (pronounced "surprise me") is always present:
    builder["*"]

    /**
    * `fast-check` will generate a seed, which is a data structure containing
    * integers that represent a kind of AST.
    *
    * To use a seed, you need to pass it to an interpreter like `vxTest.seedToSchema`,
    * `vxTest.seedToValidData` or `vxTest.seedToInvalidData`:
    */

    const [mySeed] = fc.sample(builder.object, 1)

    const mySchema = vxTest.seedToSchema(mySeed)
    // ^? const mySchema: v.ObjectSchema<unknown, unknown, v.BaseIssue<unknown>>

    const validData = vxTest.seedToValidData(mySeed)
    // ^? since the `mySeed` was also used to generate `mySchema`,
    // parsing `validData` should always succeed

    const invalidData = vxTest.seedToInvalidData(mySeed)
    // ^? since the `mySeed` was also used to generate `mySchema`,
    // parsing `invalidData` should always fail

    Namespaces

    Gen
    SchemaGenerator
    Seed
    vxTest

    Interfaces

    Builder
    GeneratorOptions
    SeedBuilder
    SeedMap

    Type Aliases

    Seed
    VERSION

    Variables

    SchemaGenerator
    SeedGenerator
    SeedInvalidDataGenerator
    SeedMap
    seedToInvalidData
    seedToValidData
    SeedValidDataGenerator
    VERSION

    Functions

    Builder
    Gen
    seedToInvalidDataGenerator
    seedToSchema
    seedToValidDataGenerator