Commit aed0051
authored
refactor(tests): migrate test suite and mock-builders to TypeScript (#3562)
## Summary
Migrates the remaining JS test infrastructure to TypeScript, then
type-tightens the whole test suite with full `noImplicitAny: true`
strictness and wires `yarn test:typecheck` into CI as a required check.
### Migration (baseline)
- 44 mock-builders (`package/src/mock-builders/`): API response
builders, event dispatchers, data generators, and the core `mock.ts`
client helper
- 36 `.test.js` files → `.test.ts` / `.test.tsx` across components and
utils
- 2 offline-support helpers → `.tsx`
- `test-utils/BetterSqlite.js` → `.ts`
- `jest-setup.js` → `.tsx` (contains JSX for the `BottomSheetModal`
mock)
- New `package/tsconfig.test.json` so tests and mock-builders are
type-checked (base `tsconfig.json` still excludes them from the
published build)
- New `yarn test:typecheck` script, wired into
`.github/workflows/check-pr.yml`
### Type-tightening
- **fix(store,messagelist):** type-annotate empty arrays in 8 source
files where `const queries = []` was inferring `never[]` under the
broader include scope. Real latent issues; no behavior change.
- **refactor(mock-builders):** tighten types in generators and event
dispatchers using SDK types from `stream-chat`; drop fields not on
`Attachment`; add missing `reminders` on default channel config; narrow
`client.channel(...)` args.
- **refactor(mock-builders): `generateMessage` now returns
`LocalMessage`.** Previously typed as `MessageResponse` but at runtime
produced `Date` objects for `created_at`/`updated_at`/`pinned_at` — the
`LocalMessage` shape. Making the type honest eliminated 33 `as unknown
as LocalMessage` casts and 57 `toLocalMessage(…)` wrapper calls across
the suite. API mocks and event dispatchers that legitimately need the
wire shape accept `MessageResponse | LocalMessage` at their boundary.
- **refactor(tests):** annotate all test bodies. Uses the established
`{...} as unknown as XContextValue` pattern for partial context mocks.
Replaces every bogus `as unknown as FileUpload` (leftover silent bug —
`FileUpload` was never imported) with the correct SDK type
(`LocalAudioAttachment` / `LocalVoiceRecordingAttachment`). Uses
`LocalAttachment` (not `Partial<Attachment>`) for attachment mocks that
set `localMetadata`. Uses `ComponentProps<typeof X>` for
`renderComponent({ props })` typings.
- **refactor(tests): flip `noImplicitAny: true`** and annotate the ~630
resulting errors across ~20 test files. `let chatClient: StreamChat`,
typed destructured params, typed `jest.fn()` callbacks,
`ComponentProps<typeof X>` for helper prop shapes. Zero `any` / `as any`
added.
### Dead-prop cleanup
Removing spread+cast and `@ts-ignore` escape hatches made TypeScript
surface a slew of props tests were passing that target components don't
actually accept. 15+ dead props removed across 16 test files. Notable:
- `MessageAuthor`: `alignment`, `groupStyles` (live on
`MessageContextValue`; `MessageAuthor` doesn't pick them).
- `MessageReplies`: `groupStyles`, `MessageRepliesAvatars`, `openThread`
(typo — real prop is `onOpenThread`; silently dropped).
- `Message`: `reactionsEnabled`, `MessageFooter` override.
- `ScrollToBottomButton`: `t` (supplied via `TranslationProvider`).
- `ChannelPreviewView`: `client`, `latestMessagePreview`, `watchers`,
`latestMessage`, `latestMessageLength`.
- `MessageList`: `channelUnreadState` (internal state, never a prop).
- `Channel`: `client` (comes from `ChatContext`, caught on
`Thread.test.tsx`).
- `Giphy` test helper: widened `Record<string, unknown>` →
`ComponentProps<typeof Giphy>`.
Also: zero `@ts-ignore` / `@ts-expect-error` directives remain in any
`*.test.*` file.
### Dependency changes
- `@types/jest`: `^29.5.14` → `^30.0.0` (matches installed `jest@30`)
- `jest`: `^30.0.0` → `^30.3.0`
- `@total-typescript/shoehorn`: new devDependency — `fromPartial<T>()`
for type-safe partial mocks, replacing `as any` / `Record<string, any>`
patterns
### Source-file changes
All zero-behavior-change type annotations:
- `src/store/apis/{addPendingTask,deleteMessage,upsertDraft}.ts`
-
`src/store/sqlite-utils/{appendOrderByClause,appendWhereCluase,createCreateTableQuery}.ts`
- `src/components/MessageList/hooks/useMessageList.ts`
- `src/components/Message/MessageItemView/utils/renderText.tsx` —
`@ts-expect-error` on the untyped `react-native-markdown-package` import
switched to `@ts-ignore` so both base and test tsconfigs agree.
### Follow-ups (out of scope)
- `package/src/store/apis/upsertDraft.ts:55` — `queries.concat(query)`
is a no-op (returns a new array that's never used). Kept out of scope
since fixing it is a behavior change on production code.
- `MessageStatus.test.tsx` had `it.each('string', fn)` (malformed —
string iterated as characters). Converted to `it.skip` to preserve
pre-migration runtime behavior. Un-skipping and rewriting is a
follow-up.
## Test plan
- [x] `yarn build` passes
- [x] `yarn lint` passes
- [x] `yarn test:typecheck` — **0 errors with `noImplicitAny: true` and
full strict mode**
- [x] `yarn test:unit` — 751 passed, 14 skipped. Only the pre-existing
SQLite-isolation flake in `offline-support/index.test.ts` fails
intermittently (baseline on develop was 5 failures; this branch is 1 —
no regressions)
- [x] Zero `@ts-ignore` / `@ts-expect-error` directives remain in any
`*.test.*` file
- [x] `yarn test:typecheck` is wired as a required check in
`.github/workflows/check-pr.yml`
- [x] CI green on push1 parent 563dcdb commit aed0051
182 files changed
Lines changed: 3346 additions & 2058 deletions
File tree
- .github/workflows
- package
- src
- __tests__/offline-support
- components
- Attachment/__tests__
- AutoCompleteInput/__tests__
- ChannelList
- __tests__
- hooks
- __tests__
- listeners/__tests__
- ChannelPreview
- __tests__
- hooks/__tests__
- Channel/__tests__
- Chat/__tests__
- ImageGallery
- __tests__
- components/__tests__
- MessageInput/__tests__
- __snapshots__
- MessageList
- __tests__
- __snapshots__
- hooks
- MessageMenu/__tests__
- Message
- MessageItemView
- __tests__
- __snapshots__
- utils
- hooks/__tests__
- Thread/__tests__
- __snapshots__
- UIComponents
- __tests__
- contexts
- messageInputContext/__tests__
- overlayContext/__tests__
- hooks/__tests__
- mock-builders
- DB
- api
- event
- generator
- state-store/__tests__
- store
- apis
- __tests__
- sqlite-utils
- test-utils
- utils/__tests__
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | | - | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
44 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
45 | 52 | | |
46 | 53 | | |
47 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
| 131 | + | |
130 | 132 | | |
131 | 133 | | |
132 | | - | |
| 134 | + | |
133 | 135 | | |
134 | 136 | | |
135 | 137 | | |
| |||
154 | 156 | | |
155 | 157 | | |
156 | 158 | | |
157 | | - | |
| 159 | + | |
158 | 160 | | |
159 | 161 | | |
160 | 162 | | |
| |||
0 commit comments