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

test: statically test types #15

Closed angeloashmore closed 3 years ago

angeloashmore commented 3 years ago

Types of changes

Description

This PR adds static tests for all public APIs. It uses ts-expect in combination with the TypeScript compiler (tsc) to determine type validity.

Tests are structured using the following order:

ts-expect was selected over other options because:

  1. It provides a simple method for testing types.
  2. It does not require separate compilers/analyzers to test types.
  3. It does not introduce a large API.

These alternatives were considered:

Checklist:

🎎

codecov-commenter commented 3 years ago

Codecov Report

Merging #15 (3025f5e) into master (05c7ea8) will not change coverage. The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##            master       #15   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines           59        59           
=========================================
  Hits            59        59           
Impacted Files Coverage Δ
src/customType.ts 100.00% <ø> (ø)
src/fields.ts 100.00% <ø> (ø)
src/index.ts 100.00% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 05c7ea8...3025f5e. Read the comment docs.

angeloashmore commented 3 years ago

+4,462 −55

For once, it's not package-lock.json causing a huge diff. 😅

You're right, it is verbose. Most of the code here is copy/pasted in each file to ensure the same test structure is used. This is something we won't need to touch often since the API is stable.

This is ready to merge if you think the general approach is good. I wanted to check with you @lihbr before merging.

lihbr commented 3 years ago

Yup, works like a charm, updated the CI workflow to run those.

Do you think we should get this setup available on the starter? Might encourage us to write a few of those elsewhere?