prismicio / prismic-types

Type definitions for Prismic content, models, and APIs
https://prismic.io/docs/technologies/javascript
Apache License 2.0
11 stars 4 forks source link

Add tests #14

Closed angeloashmore closed 2 years ago

angeloashmore commented 3 years ago

Is your feature request related to a problem? Please describe.

The library currently does not contain tests. The types should be tested against known-good data shapes.

Describe the solution you'd like

Create .ts files that are typed using the library's definitions. If the .ts files can be compiled with tsc, the tests pass.

For example, testing SelectField could look like this:

const filledSelectField1: prismicT.SelectField<"Option 1" | "Option 2", "filled"> = "Option 1"
const filledSelectField2: prismicT.SelectField<"Option 1" | "Option 2", "filled"> = "Option 2"
const emptySelectField: prismicT.SelectField<"Option 1" | "Option 2", "empty"> = null

// @ts-expect-error
const filledSelectField3: prismicT.SelectField<"Option 1" | "Option 2", "filled"> = "Option 3"
// @ts-expect-error
const filledSelectField4: prismicT.SelectField<"Option 1" | "Option 2", "filled"> = null

Describe alternatives you've considered

None.

Additional context

N/A

lihbr commented 3 years ago

That'd be great to have indeed! To me should go through a types script, update the test one and add an extra step in the CI workflow.

I'm unsure in which folder those test files should live though 🤔

angeloashmore commented 3 years ago

To me should go through a types script, update the test one and add an extra step in the CI workflow.

Yep, that makes sense to me.

I started adding tests in the aa/test branch and opened a WIP PR here: #15.

I placed type tests in /test using this file name pattern: ${category}-${specificCategory}.types.ts where:

Example: fields-image.types.ts

The type test script just runs tsc --noEmit to ensure everything compiles. If a type error is present in any of the .types.ts files, tsc will fail to compile.

angeloashmore commented 2 years ago

Completed