Skip to content

Commit e1deeb2

Browse files
authored
fix tsc errors with test files (#239)
1 parent 17fc637 commit e1deeb2

File tree

6 files changed

+67
-24
lines changed

6 files changed

+67
-24
lines changed

.github/workflows/pr-check.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ jobs:
4747
NODE_ENV: development
4848
run: pnpm install
4949

50+
# Check that packages can build without errors
51+
- name: Builds without errors
52+
env:
53+
NODE_ENV: production
54+
run: pnpm build
55+
5056
# Check for linting errors
5157
- name: Check for linting errors
5258
run: pnpm lint
5359

5460
# Check that project unit tests are successful
5561
- name: Run unit tests
5662
run: pnpm test
57-
58-
# Check that packages can build without errors
59-
- name: Builds without errors
60-
env:
61-
NODE_ENV: production
62-
run: pnpm build

justfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# run the CI workflow locally
2+
local-ci:
3+
act -W '.github/workflows/pr-check.yml' --container-architecture linux/amd64 -s GITHUB_TOKEN="$(gh auth token)"

packages/react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"test-watch": "vitest --watch",
2020
"build": "tsup",
2121
"dev": "tsup --watch",
22-
"lint": "eslint ./src",
22+
"lint": "eslint ./src && tsc --noEmit -p .",
2323
"pack": "npm pack"
2424
},
2525
"keywords": [],

packages/react/src/lib/VoiceProvider.test.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ describe('useVoice', () => {
99
it('should in', async () => {
1010
const hook = renderHook(() => useVoice(), {
1111
wrapper: ({ children }) => {
12-
return <VoiceProvider apiKey={'abc'}>{children}</VoiceProvider>;
12+
return (
13+
<VoiceProvider auth={{ type: 'apiKey', value: 'abc' }}>
14+
{children}
15+
</VoiceProvider>
16+
);
1317
},
1418
});
1519

packages/react/src/lib/useMessages.test.ts

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ describe('useMessages hook', () => {
6969

7070
beforeEach(() => {
7171
vi.clearAllMocks();
72-
hook = renderHook(() => useMessages({ sendMessageToParent }));
72+
hook = renderHook(() =>
73+
useMessages({ messageHistoryLimit: 100, sendMessageToParent }),
74+
);
7375
userMessage = {
7476
type: 'user_message',
7577
message: {
@@ -121,53 +123,82 @@ describe('useMessages hook', () => {
121123

122124
it('should add user messages to `messages` immediately', () => {
123125
act(() => {
124-
hook.result.current.onMessage(userMessage);
126+
hook.result.current.onMessage({
127+
...userMessage,
128+
receivedAt: new Date(),
129+
});
125130
});
126131

127-
expect(hook.result.current.lastUserMessage).toEqual(userMessage);
128-
expect(hook.result.current.messages).toContainEqual(userMessage);
132+
expect(hook.result.current.lastUserMessage).toMatchObject(
133+
expect.objectContaining(userMessage),
134+
);
135+
expect(hook.result.current.messages).toMatchObject(
136+
expect.arrayContaining([expect.objectContaining(userMessage)]),
137+
);
129138
});
130139

131140
it('should add voice messages to the voice message map', () => {
132141
act(() => {
133-
hook.result.current.onMessage(agentMessage);
142+
hook.result.current.onMessage({
143+
...agentMessage,
144+
receivedAt: new Date(),
145+
});
134146
});
135147

136148
expect(hook.result.current.lastVoiceMessage).toBeNull();
137-
expect(hook.result.current.messages).not.toContainEqual(agentMessage);
149+
expect(hook.result.current.messages).toMatchObject([]);
138150
});
139151

140152
it('should expose the voice message after the associated audio clip is played', () => {
141153
// add the message
142154
act(() => {
143-
hook.result.current.onMessage(agentMessage);
155+
hook.result.current.onMessage({
156+
...agentMessage,
157+
receivedAt: new Date(),
158+
});
144159
});
145160

146161
// simulate playing audio
147162
act(() => {
148163
hook.result.current.onPlayAudio(agentMessage.id ?? '');
149164
});
150165

151-
expect(hook.result.current.lastVoiceMessage).toEqual(agentMessage);
152-
expect(hook.result.current.messages).toContainEqual(agentMessage);
166+
expect(hook.result.current.lastVoiceMessage).toMatchObject(
167+
expect.objectContaining(agentMessage),
168+
);
169+
expect(hook.result.current.messages).toMatchObject(
170+
expect.arrayContaining([expect.objectContaining(agentMessage)]),
171+
);
153172
});
154173

155174
it('should expose the voice message after the associated audio clip is played', () => {
156175
act(() => {
157-
hook.result.current.onMessage(agentMessage); // First, add the message
176+
// First, add the message
177+
hook.result.current.onMessage({
178+
...agentMessage,
179+
receivedAt: new Date(),
180+
});
158181
});
159182

160183
act(() => {
161184
hook.result.current.onPlayAudio(agentMessage.id ?? '');
162185
});
163186

164-
expect(hook.result.current.lastVoiceMessage).toEqual(agentMessage);
165-
expect(hook.result.current.messages).toContainEqual(agentMessage);
187+
expect(hook.result.current.lastVoiceMessage).toMatchObject(
188+
expect.objectContaining(agentMessage),
189+
);
190+
expect(hook.result.current.messages).toMatchObject(
191+
expect.arrayContaining([expect.objectContaining(agentMessage)]),
192+
);
166193
});
167194

168195
it('should only add voice messages once', () => {
169196
act(() => {
170-
hook.result.current.onMessage(agentMessage); // First, add the message
197+
// First, add the message
198+
hook.result.current.onMessage({
199+
...agentMessage,
200+
receivedAt: new Date(),
201+
});
171202
});
172203

173204
act(() => {
@@ -186,14 +217,19 @@ describe('useMessages hook', () => {
186217

187218
it('should call the sendMessageToParent callback when the associated audio clip plays', () => {
188219
act(() => {
189-
hook.result.current.onMessage(agentMessage);
220+
hook.result.current.onMessage({
221+
...agentMessage,
222+
receivedAt: new Date(),
223+
});
190224
});
191225

192226
act(() => {
193227
hook.result.current.onPlayAudio(agentMessage.id ?? '');
194228
});
195229

196-
expect(sendMessageToParent).toHaveBeenCalledWith(agentMessage);
230+
expect(sendMessageToParent).toHaveBeenCalledWith(
231+
expect.objectContaining(agentMessage),
232+
);
197233
});
198234

199235
it('should clear all messages and states on disconnect', () => {

packages/react/src/lib/useToolStatus.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { act, renderHook } from '@testing-library/react';
2-
import type { Hume } from 'Hume';
2+
import type { Hume } from 'hume';
33
import { describe, expect, it } from 'vitest';
44

55
import { useToolStatus } from './useToolStatus';

0 commit comments

Comments
 (0)