Skip to content

Commit 12c21b3

Browse files
committed
test: fix types
1 parent c7b8b5d commit 12c21b3

File tree

2 files changed

+53
-37
lines changed

2 files changed

+53
-37
lines changed

tests/McpResponse.test.ts

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {tmpdir} from 'node:os';
99
import {join} from 'node:path';
1010
import {describe, it} from 'node:test';
1111

12+
import type {ImageContent, TextContent} from '../src/third_party/index.js';
13+
1214
import {
1315
getMockRequest,
1416
getMockResponse,
@@ -23,7 +25,7 @@ describe('McpResponse', () => {
2325
response.setIncludePages(true);
2426
const result = await response.handle('test', context);
2527
assert.equal(result[0].type, 'text');
26-
t.assert.snapshot?.(result[0].text);
28+
t.assert.snapshot?.((result[0] as TextContent).text);
2729
});
2830
});
2931

@@ -33,7 +35,7 @@ describe('McpResponse', () => {
3335
response.appendResponseLine('Testing 2');
3436
const result = await response.handle('test', context);
3537
assert.equal(result[0].type, 'text');
36-
t.assert.snapshot?.(result[0].text);
38+
t.assert.snapshot?.((result[0] as TextContent).text);
3739
});
3840
});
3941

@@ -43,7 +45,10 @@ describe('McpResponse', () => {
4345
page.accessibility.snapshot = async () => null;
4446
const result = await response.handle('test', context);
4547
assert.equal(result[0].type, 'text');
46-
assert.deepStrictEqual(result[0].text, `# test response`);
48+
assert.deepStrictEqual(
49+
(result[0] as TextContent).text,
50+
`# test response`,
51+
);
4752
});
4853
});
4954

@@ -61,7 +66,7 @@ describe('McpResponse', () => {
6166
response.includeSnapshot();
6267
const result = await response.handle('test', context);
6368
assert.equal(result[0].type, 'text');
64-
t.assert.snapshot?.(result[0].text);
69+
t.assert.snapshot?.((result[0] as TextContent).text);
6570
});
6671
});
6772

@@ -79,7 +84,7 @@ describe('McpResponse', () => {
7984
response.includeSnapshot();
8085
const result = await response.handle('test', context);
8186
assert.equal(result[0].type, 'text');
82-
t.assert.snapshot?.(result[0].text);
87+
t.assert.snapshot?.((result[0] as TextContent).text);
8388
});
8489
});
8590

@@ -92,7 +97,7 @@ describe('McpResponse', () => {
9297
});
9398
const result = await response.handle('test', context);
9499
assert.equal(result[0].type, 'text');
95-
t.assert.snapshot?.(result[0].text);
100+
t.assert.snapshot?.((result[0] as TextContent).text);
96101
});
97102
});
98103

@@ -108,7 +113,9 @@ describe('McpResponse', () => {
108113
});
109114
const result = await response.handle('test', context);
110115
assert.equal(result[0].type, 'text');
111-
t.assert.snapshot?.(stabilizeResponseOutput(result[0].text));
116+
t.assert.snapshot?.(
117+
stabilizeResponseOutput((result[0] as TextContent).text),
118+
);
112119
});
113120
const content = await readFile(filePath, 'utf-8');
114121
t.assert.snapshot?.(stabilizeResponseOutput(content));
@@ -122,7 +129,7 @@ describe('McpResponse', () => {
122129
context.setNetworkConditions('Slow 3G');
123130
const result = await response.handle('test', context);
124131
assert.equal(result[0].type, 'text');
125-
t.assert.snapshot?.(result[0].text);
132+
t.assert.snapshot?.((result[0] as TextContent).text);
126133
});
127134
});
128135

@@ -131,33 +138,33 @@ describe('McpResponse', () => {
131138
const result = await response.handle('test', context);
132139
context.setNetworkConditions(null);
133140
assert.equal(result[0].type, 'text');
134-
assert.strictEqual(result[0].text, `# test response`);
141+
assert.strictEqual((result[0] as TextContent).text, `# test response`);
135142
});
136143
});
137144
it('adds image when image is attached', async () => {
138145
await withBrowser(async (response, context) => {
139146
response.attachImage({data: 'imageBase64', mimeType: 'image/png'});
140147
const result = await response.handle('test', context);
141-
assert.strictEqual(result[0].text, `# test response`);
148+
assert.strictEqual((result[0] as TextContent).text, `# test response`);
142149
assert.equal(result[1].type, 'image');
143-
assert.strictEqual(result[1].data, 'imageBase64');
144-
assert.strictEqual(result[1].mimeType, 'image/png');
150+
assert.strictEqual((result[1] as ImageContent).data, 'imageBase64');
151+
assert.strictEqual((result[1] as ImageContent).mimeType, 'image/png');
145152
});
146153
});
147154

148155
it('adds cpu throttling setting when it is over 1', async t => {
149156
await withBrowser(async (response, context) => {
150157
context.setCpuThrottlingRate(4);
151158
const result = await response.handle('test', context);
152-
t.assert.snapshot?.(result[0].text);
159+
t.assert.snapshot?.((result[0] as TextContent).text);
153160
});
154161
});
155162

156163
it('does not include cpu throttling setting when it is 1', async () => {
157164
await withBrowser(async (response, context) => {
158165
context.setCpuThrottlingRate(1);
159166
const result = await response.handle('test', context);
160-
assert.strictEqual(result[0].text, `# test response`);
167+
assert.strictEqual((result[0] as TextContent).text, `# test response`);
161168
});
162169
});
163170

@@ -175,7 +182,7 @@ describe('McpResponse', () => {
175182
await dialogPromise;
176183
const result = await response.handle('test', context);
177184
await context.getDialog()?.dismiss();
178-
t.assert.snapshot?.(result[0].text);
185+
t.assert.snapshot?.((result[0] as TextContent).text);
179186
});
180187
});
181188

@@ -193,7 +200,7 @@ describe('McpResponse', () => {
193200
await dialogPromise;
194201
const result = await response.handle('test', context);
195202
await context.getDialog()?.dismiss();
196-
t.assert.snapshot?.(result[0].text);
203+
t.assert.snapshot?.((result[0] as TextContent).text);
197204
});
198205
});
199206

@@ -204,7 +211,7 @@ describe('McpResponse', () => {
204211
return [getMockRequest({stableId: 1}), getMockRequest({stableId: 2})];
205212
};
206213
const result = await response.handle('test', context);
207-
t.assert.snapshot?.(result[0].text);
214+
t.assert.snapshot?.((result[0] as TextContent).text);
208215
});
209216
});
210217

@@ -215,7 +222,7 @@ describe('McpResponse', () => {
215222
return [getMockRequest()];
216223
};
217224
const result = await response.handle('test', context);
218-
assert.strictEqual(result[0].text, `# test response`);
225+
assert.strictEqual((result[0] as TextContent).text, `# test response`);
219226
});
220227
});
221228

@@ -247,7 +254,7 @@ describe('McpResponse', () => {
247254

248255
const result = await response.handle('test', context);
249256

250-
t.assert.snapshot?.(result[0].text);
257+
t.assert.snapshot?.((result[0] as TextContent).text);
251258
});
252259
});
253260

@@ -263,7 +270,7 @@ describe('McpResponse', () => {
263270
};
264271
response.attachNetworkRequest(1);
265272
const result = await response.handle('test', context);
266-
t.assert.snapshot?.(result[0].text);
273+
t.assert.snapshot?.((result[0] as TextContent).text);
267274
});
268275
});
269276

@@ -281,17 +288,17 @@ describe('McpResponse', () => {
281288
});
282289
await consoleMessagePromise;
283290
const result = await response.handle('test', context);
284-
assert.ok(result[0].text);
285-
t.assert.snapshot?.(result[0].text);
291+
assert.ok((result[0] as TextContent).text);
292+
t.assert.snapshot?.((result[0] as TextContent).text);
286293
});
287294
});
288295

289296
it('adds a message when no console messages exist', async t => {
290297
await withBrowser(async (response, context) => {
291298
response.setIncludeConsoleData(true);
292299
const result = await response.handle('test', context);
293-
assert.ok(result[0].text);
294-
t.assert.snapshot?.(result[0].text);
300+
assert.ok((result[0] as TextContent).text);
301+
t.assert.snapshot?.((result[0] as TextContent).text);
295302
});
296303
});
297304
});
@@ -311,7 +318,7 @@ describe('McpResponse network request filtering', () => {
311318
];
312319
};
313320
const result = await response.handle('test', context);
314-
t.assert.snapshot?.(result[0].text);
321+
t.assert.snapshot?.((result[0] as TextContent).text);
315322
});
316323
});
317324

@@ -328,7 +335,7 @@ describe('McpResponse network request filtering', () => {
328335
];
329336
};
330337
const result = await response.handle('test', context);
331-
t.assert.snapshot?.(result[0].text);
338+
t.assert.snapshot?.((result[0] as TextContent).text);
332339
});
333340
});
334341

@@ -345,7 +352,7 @@ describe('McpResponse network request filtering', () => {
345352
];
346353
};
347354
const result = await response.handle('test', context);
348-
t.assert.snapshot?.(result[0].text);
355+
t.assert.snapshot?.((result[0] as TextContent).text);
349356
});
350357
});
351358

@@ -363,7 +370,7 @@ describe('McpResponse network request filtering', () => {
363370
};
364371
const result = await response.handle('test', context);
365372

366-
t.assert.snapshot?.(result[0].text);
373+
t.assert.snapshot?.((result[0] as TextContent).text);
367374
});
368375
});
369376

@@ -382,7 +389,7 @@ describe('McpResponse network request filtering', () => {
382389
];
383390
};
384391
const result = await response.handle('test', context);
385-
t.assert.snapshot?.(result[0].text);
392+
t.assert.snapshot?.((result[0] as TextContent).text);
386393
});
387394
});
388395
});
@@ -394,7 +401,7 @@ describe('McpResponse network pagination', () => {
394401
context.getNetworkRequests = () => requests;
395402
response.setIncludeNetworkRequests(true);
396403
const result = await response.handle('test', context);
397-
const text = (result[0].text as string).toString();
404+
const text = ((result[0] as TextContent).text as string).toString();
398405
assert.ok(text.includes('Showing 1-5 of 5 (Page 1 of 1).'));
399406
assert.ok(!text.includes('Next page:'));
400407
assert.ok(!text.includes('Previous page:'));
@@ -411,7 +418,7 @@ describe('McpResponse network pagination', () => {
411418
};
412419
response.setIncludeNetworkRequests(true, {pageSize: 10});
413420
const result = await response.handle('test', context);
414-
const text = (result[0].text as string).toString();
421+
const text = ((result[0] as TextContent).text as string).toString();
415422
assert.ok(text.includes('Showing 1-10 of 30 (Page 1 of 3).'));
416423
assert.ok(text.includes('Next page: 1'));
417424
assert.ok(!text.includes('Previous page:'));
@@ -429,7 +436,7 @@ describe('McpResponse network pagination', () => {
429436
pageIdx: 1,
430437
});
431438
const result = await response.handle('test', context);
432-
const text = (result[0].text as string).toString();
439+
const text = ((result[0] as TextContent).text as string).toString();
433440
assert.ok(text.includes('Showing 11-20 of 25 (Page 2 of 3).'));
434441
assert.ok(text.includes('Next page: 2'));
435442
assert.ok(text.includes('Previous page: 0'));
@@ -445,7 +452,7 @@ describe('McpResponse network pagination', () => {
445452
pageIdx: 10, // Invalid page number
446453
});
447454
const result = await response.handle('test', context);
448-
const text = (result[0].text as string).toString();
455+
const text = ((result[0] as TextContent).text as string).toString();
449456
assert.ok(
450457
text.includes('Invalid page number provided. Showing first page.'),
451458
);

tests/tools/network.test.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import assert from 'node:assert';
77
import {describe, it} from 'node:test';
88

9+
import type {TextContent} from '../../src/third_party/index.js';
910
import {
1011
getNetworkRequest,
1112
listNetworkRequests,
@@ -43,7 +44,9 @@ describe('network', () => {
4344
context,
4445
);
4546
const responseData = await response.handle('list_request', context);
46-
t.assert.snapshot?.(stabilizeResponseOutput(responseData[0].text));
47+
t.assert.snapshot?.(
48+
stabilizeResponseOutput((responseData[0] as TextContent).text),
49+
);
4750
});
4851
});
4952

@@ -68,7 +71,9 @@ describe('network', () => {
6871
context,
6972
);
7073
const responseData = await response.handle('list_request', context);
71-
t.assert.snapshot?.(stabilizeResponseOutput(responseData[0].text));
74+
t.assert.snapshot?.(
75+
stabilizeResponseOutput((responseData[0] as TextContent).text),
76+
);
7277
});
7378
});
7479

@@ -106,7 +111,9 @@ describe('network', () => {
106111
context,
107112
);
108113
const responseData = await response.handle('list_request', context);
109-
t.assert.snapshot?.(stabilizeResponseOutput(responseData[0].text));
114+
t.assert.snapshot?.(
115+
stabilizeResponseOutput((responseData[0] as TextContent).text),
116+
);
110117
});
111118
});
112119
});
@@ -158,7 +165,9 @@ describe('network', () => {
158165
);
159166
const responseData = await response.handle('get_request', context);
160167

161-
t.assert.snapshot?.(stabilizeResponseOutput(responseData[0].text));
168+
t.assert.snapshot?.(
169+
stabilizeResponseOutput((responseData[0] as TextContent).text),
170+
);
162171
});
163172
});
164173
});

0 commit comments

Comments
 (0)