Commit 9877da5
authored
chore: migrate test suite from JavaScript to TypeScript (#3057)
### 🎯 Goal
Migrate the entire test suite from JavaScript/JSX to TypeScript/TSX to
improve IDE autocompletion, refactoring safety, and catch type errors at
write time. Also replace ad-hoc `as any` casts with proper SDK types and
typed test helpers.
### 🛠 Implementation details
**Scope:** 248 files changed, 3725 insertions, 2411 deletions
#### Infrastructure
- Install `@total-typescript/shoehorn` for `fromPartial<T>()` in test
mocks
- Update `tsconfig.test.json` with proper include patterns, path
aliases, and 4 strict flags (`strictBindCallApply`, `noImplicitThis`,
`alwaysStrict`, `useUnknownInCatchVariables`)
- Update `eslint.config.mjs` with test-specific rule relaxations; enable
`disallowTypeAnnotations: false` for `typeof import()` in `vi.mock`
- Add `@vitest/expect` module augmentation for jest-dom + vitest-axe
matchers (vitest 4.x compatibility)
- Add `yarn types:tests` script for test type-checking
- Exclude test files from i18next translation extraction
(`i18next.config.ts`)
#### Mock-builders (45 JS → TS)
- All generators typed with SDK types (`UserResponse`, `Attachment`,
`ReactionResponse`, `ChannelMemberResponse`, `LocalMessage`,
`PollResponse`, `ChannelAPIResponse`, etc.)
- `generateMessage()` returns `LocalMessage` (matches what components
consume) and accepts `Date | string` for date fields
- `generateChannel()` returns `ChannelAPIResponse` (renamed
`pinnedMessages` → `pinned_messages`)
- `mockClient` typed with `StreamChat`, uses `vi.spyOn` for public
methods
- `MockClientOverrides` interface using `StreamChat['getAppSettings']`
and `StreamChat['queryReactions']`
- `TokenManager` typed with `fromPartial<TokenManager>()`
- `getOrCreateChannelApi` typed with `ChannelAPIResponse`,
`queryChannelsApi` with `ChannelAPIResponse[]`
- `sendMessageApi` typed with `MessageResponse | LocalMessage`
- Event dispatchers use `fromPartial<Event>()`, accept `Channel |
ChannelResponse` and `MessageResponse | LocalMessage`
- `TDateTimeParser` from `i18n/types` used for translation mock
- `ResizeObserverCallback` DOM type, `Partial<BlobEvent>`,
`Partial<File>`, `Action` from SDK
- 9 typed context builder helpers (`mockChatContext`,
`mockChannelStateContext`, `mockTranslationContextValue`, etc.)
#### Test files (134 JS/JSX → TS/TSX)
- All 1,720 type errors fixed
- `as any` reduced from ~1,107 to ~435 (61% reduction)
- `Record<string, any>` reduced to 0 — all replaced with typed
interfaces
- Provider `value as any` replaced with context helpers
(`mockChatContext()`, etc.)
- `vi.spyOn(obj as any)` replaced with `@ts-expect-error` + proper spy
- `{} as any` replaced with `fromPartial<Type>({})`
- `importOriginal() as any` replaced with `importOriginal<typeof
import('...')>()`
- Private property access uses bracket notation (`obj['prop']`) instead
of `(obj as any).prop`
- `renderComponent` params typed with per-file interfaces using SDK
types
- Variables typed as `StreamChat`, `Channel`, `LocalMessage` instead of
`any`
- `{ children }: any` replaced with `React.PropsWithChildren`
- Removed no-op `amplitudesCount` prop from WaveProgressBar tests
- Deleted 19 orphan `.test.jsx.snap` snapshot files
#### Remaining `as any` (~435, intentionally kept)
| Category | Count | Reason |
|----------|-------|--------|
| Partial objects in component/hook tests | ~149 | Test data does not
satisfy full type; `fromPartial` used where possible |
| TFunction mock (`$TFunctionBrand`) | ~35 | i18next brand symbol cannot
be satisfied by mock functions |
| `LocalMessage[]` → `MessageResponse[]` | ~42 | Date vs string field
mismatch in `generateChannel` calls |
| `window/navigator/globalThis` | ~17 | Read-only DOM globals |
| `@ts-expect-error` (explicit) | ~18 | Mock impl signature mismatches,
properly documented |
| Mouse event mocks | ~16 | Partial event objects |
| `.next(value)` on state/subjects | ~12 | BehaviorSubject type
constraints |
| Misc (channel, client, renderText) | ~146 | Scattered partials and
legacy patterns |
### 🎨 UI Changes
No UI changes — test infrastructure only.1 parent a55774d commit 9877da5
248 files changed
Lines changed: 3725 additions & 2411 deletions
File tree
- src
- @types
- components
- Attachment/__tests__
- __snapshots__
- AudioPlayback
- __tests__
- plugins/__tests__
- Avatar/__tests__
- BaseImage/__tests__
- ChannelHeader/__tests__
- ChannelListItem
- __tests__
- __snapshots__
- hooks/__tests__
- ChannelList/__tests__
- __snapshots__
- Channel/__tests__
- __snapshots__
- ChatView/__tests__
- Chat/__tests__
- DateSeparator/__tests__
- Dialog/__tests__
- EmptyStateIndicator/__tests__
- EventComponent/__tests__
- Form/__tests__
- Gallery/__tests__
- __snapshots__
- InfiniteScrollPaginator/__tests__
- LoadMore/__tests__
- Loading/__tests__
- __snapshots__
- Location/__tests__
- MediaRecorder
- AudioRecorder/__tests__
- __snapshots__
- classes/__tests__
- hooks/__tests__
- observable/__tests__
- MessageActions/__tests__
- MessageComposer
- __tests__
- __snapshots__
- hooks/__tests__
- MessageList
- __tests__
- __snapshots__
- hooks/__tests__
- Message
- __tests__
- __snapshots__
- hooks/__tests__
- renderText/__tests__
- __snapshots__
- Modal/__tests__
- Notifications
- __tests__
- hooks/__tests__
- Poll/__tests__
- Reactions/__tests__
- SafeAnchor/__tests__
- Search/__tests__
- TextareaComposer/__tests__
- Threads/ThreadList/__tests__
- Thread/__tests__
- Tooltip/__tests__
- TypingIndicator
- __tests__
- hooks/__tests__
- Window/__tests__
- i18n/__tests__
- mock-builders
- __test__
- api
- browser
- events
- event
- generator
- 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 | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
| 119 | + | |
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
133 | 139 | | |
134 | 140 | | |
135 | 141 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
| 148 | + | |
148 | 149 | | |
149 | 150 | | |
150 | 151 | | |
| |||
203 | 204 | | |
204 | 205 | | |
205 | 206 | | |
| 207 | + | |
206 | 208 | | |
207 | 209 | | |
208 | 210 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
Lines changed: 11 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
| 39 | + | |
36 | 40 | | |
37 | | - | |
| 41 | + | |
38 | 42 | | |
39 | 43 | | |
40 | 44 | | |
| |||
56 | 60 | | |
57 | 61 | | |
58 | 62 | | |
59 | | - | |
| 63 | + | |
60 | 64 | | |
61 | 65 | | |
62 | 66 | | |
| |||
258 | 262 | | |
259 | 263 | | |
260 | 264 | | |
261 | | - | |
| 265 | + | |
262 | 266 | | |
263 | | - | |
| 267 | + | |
264 | 268 | | |
265 | | - | |
| 269 | + | |
266 | 270 | | |
267 | | - | |
| 271 | + | |
268 | 272 | | |
269 | 273 | | |
270 | 274 | | |
| |||
Lines changed: 18 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
6 | 10 | | |
7 | 11 | | |
8 | 12 | | |
| |||
33 | 37 | | |
34 | 38 | | |
35 | 39 | | |
36 | | - | |
| 40 | + | |
37 | 41 | | |
38 | 42 | | |
39 | | - | |
| 43 | + | |
40 | 44 | | |
41 | 45 | | |
42 | 46 | | |
| |||
79 | 83 | | |
80 | 84 | | |
81 | 85 | | |
82 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
83 | 89 | | |
84 | 90 | | |
85 | 91 | | |
| |||
96 | 102 | | |
97 | 103 | | |
98 | 104 | | |
99 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
100 | 108 | | |
101 | 109 | | |
102 | 110 | | |
| |||
118 | 126 | | |
119 | 127 | | |
120 | 128 | | |
121 | | - | |
| 129 | + | |
122 | 130 | | |
123 | 131 | | |
124 | 132 | | |
| |||
265 | 273 | | |
266 | 274 | | |
267 | 275 | | |
268 | | - | |
| 276 | + | |
269 | 277 | | |
270 | 278 | | |
271 | | - | |
| 279 | + | |
272 | 280 | | |
273 | 281 | | |
274 | 282 | | |
| |||
287 | 295 | | |
288 | 296 | | |
289 | 297 | | |
290 | | - | |
| 298 | + | |
291 | 299 | | |
292 | 300 | | |
293 | | - | |
| 301 | + | |
294 | 302 | | |
295 | 303 | | |
296 | 304 | | |
| |||
Lines changed: 23 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
11 | 15 | | |
12 | 16 | | |
13 | 17 | | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
18 | | - | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
19 | 26 | | |
20 | 27 | | |
21 | 28 | | |
22 | 29 | | |
23 | | - | |
24 | | - | |
| 30 | + | |
| 31 | + | |
25 | 32 | | |
26 | 33 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
31 | 38 | | |
32 | 39 | | |
33 | 40 | | |
34 | 41 | | |
35 | | - | |
36 | | - | |
| 42 | + | |
| 43 | + | |
37 | 44 | | |
38 | | - | |
| 45 | + | |
39 | 46 | | |
40 | | - | |
41 | | - | |
| 47 | + | |
| 48 | + | |
42 | 49 | | |
43 | | - | |
44 | | - | |
| 50 | + | |
| 51 | + | |
45 | 52 | | |
46 | 53 | | |
47 | 54 | | |
| |||
56 | 63 | | |
57 | 64 | | |
58 | 65 | | |
59 | | - | |
| 66 | + | |
60 | 67 | | |
61 | 68 | | |
62 | 69 | | |
| |||
75 | 82 | | |
76 | 83 | | |
77 | 84 | | |
78 | | - | |
| 85 | + | |
79 | 86 | | |
80 | 87 | | |
81 | 88 | | |
| |||
Lines changed: 5 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
| 5 | + | |
| 6 | + | |
7 | 7 | | |
8 | | - | |
9 | | - | |
| 8 | + | |
| 9 | + | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
0 commit comments