@traversable/schema
    Preparing search index...

    Module @traversable/arktype-test - v0.0.20


    ᯓ𝘁𝗿𝗮𝘃𝗲𝗿𝘀𝗮𝗯𝗹𝗲/𝗮𝗿𝗸𝘁𝘆𝗽𝗲-𝘁𝗲𝘀𝘁


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

    NPM Version   TypeScript   License   npm  
    Static Badge   Static Badge   Static Badge  


    @traversable/arktype-test has 2 peer dependencies:

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

    Here's an example of importing the library:

    import { type } from 'arktype'
    import { arkTest } from '@traversable/arktype-test'

    // see below for specifc examples

    @traversable/arktype-test has found several upstream bugs:

    1. Array + tuple union unsatisfied by empty array
    1. Discriminated union bug

    Use arkTest.seedToSchema to convert a seed generated by arkTest.SeedGenerator into an ArkType schema that satisfies the configuration options you specified.

    import { type } from 'arktype'
    import { arkTest } from '@traversable/arktype-test'
    import * as fc from 'fast-check'

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

    const mySchema = arkTest.seedToSchema(mySeed)
    // ^? const mySchema: type.Any

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

    import { type } from 'arktype'
    import { arkTest } from '@traversable/arktype-test'
    import * as fc from 'fast-check'

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

    const mySchema = arkTest.seedToSchema(mySeed)
    // ^? const mySchema: type.Any

    const validData = arkTest.seedToValidData(mySeed)

    mySchema(validData) instanceof type.errors // always `false`

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

    import { type } from 'arktype'
    import { arkTest } from '@traversable/arktype-test'
    import * as fc from 'fast-check'

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

    const mySchema = arkTest.seedToSchema(mySeed)
    // ^? const mySchema: type.Any

    const invalidData = arkTest.seedToValidData(mySeed)

    mySchema(invalidData) instanceof type.errors // always `true`
    Note

    arkTest.SeedGenerator is fairly low-level. All of the other exports of this library have been implemented in terms of arkTest.SeedGenerator.

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

    import { type } from 'arktype'
    import * as fc from 'fast-check'
    import { arkTest } from '@traversable/arktype-test'

    const builder = arkTest.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`)
    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 `arkTest.seedToSchema`,
    * `arkTest.seedToValidData` or `arkTest.seedToInvalidData`:
    */

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

    const mySchema = arkTest.seedToSchema(mySeed)
    // ^? const mySchema: type.Any

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

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

    Like arkTest.SeedGenerator, except arkTest.SeedValidDataGenerator comes pre-configured to exclude schemas that make it impossible to reliably generate valid data.

    Note

    arkTest.SeedValidDataGenerator does not accept any options. If you need more fine-grained control of the schemas being generated, use arkTest.SeedGenerator.

    Like arkTest.SeedGenerator, except arkTest.SeedValidDataGenerator comes pre-configured to exclude schemas that make it impossible to reliably generate invalid data.

    Note

    arkTest.SeedInvalidDataGenerator does not accept any options. If you need more fine-grained control of the schemas being generated, use arkTest.SeedGenerator.

    Namespaces

    arkTest
    Gen
    SchemaGenerator
    Seed

    Interfaces

    Builder
    SeedMap

    Type Aliases

    GeneratorOptions
    Seed
    VERSION

    Variables

    pickAndSortNodes
    SchemaGenerator
    SeedGenerator
    SeedInvalidDataGenerator
    SeedMap
    seedToInvalidData
    seedToValidData
    SeedValidDataGenerator
    VERSION

    Functions

    Builder
    Gen
    isTerminal
    seedToInvalidDataGenerator
    seedToSchema
    seedToValidDataGenerator