Automattic / Automattic/wp-calypso

Better support TypeScript unit testing in packages

Open
#54,801 3 comments 0 reactions 0 assignees View on GitHub
Tooling
Dominant language
TypeScript
Stars
12.6k
Forks
2k
Avg merge
1d 17h
Merged PRs (30d)
552

Description

## Overview

Currently, our overall set up and yarn scripts make it a little tricky to have optimal TypeScript support for unit tests in `packages`. This is because we re-use the same `tsconfig.json` files for both build and type-checking in our various yarn scripts an CI pipelines. The result is that most folks either include their unit tests in the package `dist` output (and then prune later if needed), or just completely exclude their unit tests from any `tsconfig` based type checking at all (this is the current majority)!

## Options

We first need to decide how we want to handle type checking for unit tests: do we want to do it holistically as a separate step? Or do we want to type check unit tests at the time of running them?

Based on that, there are a few places we could go from there:

1. Update our various yarn scripts and CI builds to do a dedicated unit test type check (perhaps doing a glob match for files named `tsconfig.test.json`.
2. Start using a type-checking transformer in Jest, like [ts-jest](https://www.npmjs.com/package/ts-jest)

My personal 0.02 is that for unit tests we should move over to checking types at unit test run time, and do it using a transformer like ts-jest.

For more background, see [this comment](https://github.com/Automattic/wp-calypso/pull/54734#issuecomment-884637006).

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the package tsconfig.json files, yarn scripts, and CI pipelines described in the issue. Compare the proposed dedicated type-check step with using a Jest transformer such as ts-jest, using the linked pull-request comment for context. Done requires an agreed approach that gives package unit tests consistent TypeScript checking without unnecessarily including them in build output.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system, ci-cd, testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.