Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"mcpName": "io.github.ChromeDevTools/chrome-devtools-mcp",
"devDependencies": {
"@eslint/js": "^9.35.0",
"@modelcontextprotocol/sdk": "1.21.1",
"@modelcontextprotocol/sdk": "1.22.0",
"@rollup/plugin-commonjs": "^29.0.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^16.0.3",
Expand Down
73 changes: 40 additions & 33 deletions tests/McpResponse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {tmpdir} from 'node:os';
import {join} from 'node:path';
import {describe, it} from 'node:test';

import type {ImageContent, TextContent} from '../src/third_party/index.js';

import {
getMockRequest,
getMockResponse,
Expand All @@ -23,7 +25,7 @@ describe('McpResponse', () => {
response.setIncludePages(true);
const result = await response.handle('test', context);
assert.equal(result[0].type, 'text');
t.assert.snapshot?.(result[0].text);
t.assert.snapshot?.((result[0] as TextContent).text);
});
});

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

Expand All @@ -43,7 +45,10 @@ describe('McpResponse', () => {
page.accessibility.snapshot = async () => null;
const result = await response.handle('test', context);
assert.equal(result[0].type, 'text');
assert.deepStrictEqual(result[0].text, `# test response`);
assert.deepStrictEqual(
(result[0] as TextContent).text,
`# test response`,
);
});
});

Expand All @@ -61,7 +66,7 @@ describe('McpResponse', () => {
response.includeSnapshot();
const result = await response.handle('test', context);
assert.equal(result[0].type, 'text');
t.assert.snapshot?.(result[0].text);
t.assert.snapshot?.((result[0] as TextContent).text);
});
});

Expand All @@ -79,7 +84,7 @@ describe('McpResponse', () => {
response.includeSnapshot();
const result = await response.handle('test', context);
assert.equal(result[0].type, 'text');
t.assert.snapshot?.(result[0].text);
t.assert.snapshot?.((result[0] as TextContent).text);
});
});

Expand All @@ -92,7 +97,7 @@ describe('McpResponse', () => {
});
const result = await response.handle('test', context);
assert.equal(result[0].type, 'text');
t.assert.snapshot?.(result[0].text);
t.assert.snapshot?.((result[0] as TextContent).text);
});
});

Expand All @@ -108,7 +113,9 @@ describe('McpResponse', () => {
});
const result = await response.handle('test', context);
assert.equal(result[0].type, 'text');
t.assert.snapshot?.(stabilizeResponseOutput(result[0].text));
t.assert.snapshot?.(
stabilizeResponseOutput((result[0] as TextContent).text),
);
});
const content = await readFile(filePath, 'utf-8');
t.assert.snapshot?.(stabilizeResponseOutput(content));
Expand All @@ -122,7 +129,7 @@ describe('McpResponse', () => {
context.setNetworkConditions('Slow 3G');
const result = await response.handle('test', context);
assert.equal(result[0].type, 'text');
t.assert.snapshot?.(result[0].text);
t.assert.snapshot?.((result[0] as TextContent).text);
});
});

Expand All @@ -131,33 +138,33 @@ describe('McpResponse', () => {
const result = await response.handle('test', context);
context.setNetworkConditions(null);
assert.equal(result[0].type, 'text');
assert.strictEqual(result[0].text, `# test response`);
assert.strictEqual((result[0] as TextContent).text, `# test response`);
});
});
it('adds image when image is attached', async () => {
await withBrowser(async (response, context) => {
response.attachImage({data: 'imageBase64', mimeType: 'image/png'});
const result = await response.handle('test', context);
assert.strictEqual(result[0].text, `# test response`);
assert.strictEqual((result[0] as TextContent).text, `# test response`);
assert.equal(result[1].type, 'image');
assert.strictEqual(result[1].data, 'imageBase64');
assert.strictEqual(result[1].mimeType, 'image/png');
assert.strictEqual((result[1] as ImageContent).data, 'imageBase64');
assert.strictEqual((result[1] as ImageContent).mimeType, 'image/png');
});
});

it('adds cpu throttling setting when it is over 1', async t => {
await withBrowser(async (response, context) => {
context.setCpuThrottlingRate(4);
const result = await response.handle('test', context);
t.assert.snapshot?.(result[0].text);
t.assert.snapshot?.((result[0] as TextContent).text);
});
});

it('does not include cpu throttling setting when it is 1', async () => {
await withBrowser(async (response, context) => {
context.setCpuThrottlingRate(1);
const result = await response.handle('test', context);
assert.strictEqual(result[0].text, `# test response`);
assert.strictEqual((result[0] as TextContent).text, `# test response`);
});
});

Expand All @@ -175,7 +182,7 @@ describe('McpResponse', () => {
await dialogPromise;
const result = await response.handle('test', context);
await context.getDialog()?.dismiss();
t.assert.snapshot?.(result[0].text);
t.assert.snapshot?.((result[0] as TextContent).text);
});
});

Expand All @@ -193,7 +200,7 @@ describe('McpResponse', () => {
await dialogPromise;
const result = await response.handle('test', context);
await context.getDialog()?.dismiss();
t.assert.snapshot?.(result[0].text);
t.assert.snapshot?.((result[0] as TextContent).text);
});
});

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

Expand All @@ -215,7 +222,7 @@ describe('McpResponse', () => {
return [getMockRequest()];
};
const result = await response.handle('test', context);
assert.strictEqual(result[0].text, `# test response`);
assert.strictEqual((result[0] as TextContent).text, `# test response`);
});
});

Expand Down Expand Up @@ -247,7 +254,7 @@ describe('McpResponse', () => {

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

t.assert.snapshot?.(result[0].text);
t.assert.snapshot?.((result[0] as TextContent).text);
});
});

Expand All @@ -263,7 +270,7 @@ describe('McpResponse', () => {
};
response.attachNetworkRequest(1);
const result = await response.handle('test', context);
t.assert.snapshot?.(result[0].text);
t.assert.snapshot?.((result[0] as TextContent).text);
});
});

Expand All @@ -281,17 +288,17 @@ describe('McpResponse', () => {
});
await consoleMessagePromise;
const result = await response.handle('test', context);
assert.ok(result[0].text);
t.assert.snapshot?.(result[0].text);
assert.ok((result[0] as TextContent).text);
t.assert.snapshot?.((result[0] as TextContent).text);
});
});

it('adds a message when no console messages exist', async t => {
await withBrowser(async (response, context) => {
response.setIncludeConsoleData(true);
const result = await response.handle('test', context);
assert.ok(result[0].text);
t.assert.snapshot?.(result[0].text);
assert.ok((result[0] as TextContent).text);
t.assert.snapshot?.((result[0] as TextContent).text);
});
});
});
Expand All @@ -311,7 +318,7 @@ describe('McpResponse network request filtering', () => {
];
};
const result = await response.handle('test', context);
t.assert.snapshot?.(result[0].text);
t.assert.snapshot?.((result[0] as TextContent).text);
});
});

Expand All @@ -328,7 +335,7 @@ describe('McpResponse network request filtering', () => {
];
};
const result = await response.handle('test', context);
t.assert.snapshot?.(result[0].text);
t.assert.snapshot?.((result[0] as TextContent).text);
});
});

Expand All @@ -345,7 +352,7 @@ describe('McpResponse network request filtering', () => {
];
};
const result = await response.handle('test', context);
t.assert.snapshot?.(result[0].text);
t.assert.snapshot?.((result[0] as TextContent).text);
});
});

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

t.assert.snapshot?.(result[0].text);
t.assert.snapshot?.((result[0] as TextContent).text);
});
});

Expand All @@ -382,7 +389,7 @@ describe('McpResponse network request filtering', () => {
];
};
const result = await response.handle('test', context);
t.assert.snapshot?.(result[0].text);
t.assert.snapshot?.((result[0] as TextContent).text);
});
});
});
Expand All @@ -394,7 +401,7 @@ describe('McpResponse network pagination', () => {
context.getNetworkRequests = () => requests;
response.setIncludeNetworkRequests(true);
const result = await response.handle('test', context);
const text = (result[0].text as string).toString();
const text = ((result[0] as TextContent).text as string).toString();
assert.ok(text.includes('Showing 1-5 of 5 (Page 1 of 1).'));
assert.ok(!text.includes('Next page:'));
assert.ok(!text.includes('Previous page:'));
Expand All @@ -411,7 +418,7 @@ describe('McpResponse network pagination', () => {
};
response.setIncludeNetworkRequests(true, {pageSize: 10});
const result = await response.handle('test', context);
const text = (result[0].text as string).toString();
const text = ((result[0] as TextContent).text as string).toString();
assert.ok(text.includes('Showing 1-10 of 30 (Page 1 of 3).'));
assert.ok(text.includes('Next page: 1'));
assert.ok(!text.includes('Previous page:'));
Expand All @@ -429,7 +436,7 @@ describe('McpResponse network pagination', () => {
pageIdx: 1,
});
const result = await response.handle('test', context);
const text = (result[0].text as string).toString();
const text = ((result[0] as TextContent).text as string).toString();
assert.ok(text.includes('Showing 11-20 of 25 (Page 2 of 3).'));
assert.ok(text.includes('Next page: 2'));
assert.ok(text.includes('Previous page: 0'));
Expand All @@ -445,7 +452,7 @@ describe('McpResponse network pagination', () => {
pageIdx: 10, // Invalid page number
});
const result = await response.handle('test', context);
const text = (result[0].text as string).toString();
const text = ((result[0] as TextContent).text as string).toString();
assert.ok(
text.includes('Invalid page number provided. Showing first page.'),
);
Expand Down
17 changes: 13 additions & 4 deletions tests/tools/network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import assert from 'node:assert';
import {describe, it} from 'node:test';

import type {TextContent} from '../../src/third_party/index.js';
import {
getNetworkRequest,
listNetworkRequests,
Expand Down Expand Up @@ -43,7 +44,9 @@ describe('network', () => {
context,
);
const responseData = await response.handle('list_request', context);
t.assert.snapshot?.(stabilizeResponseOutput(responseData[0].text));
t.assert.snapshot?.(
stabilizeResponseOutput((responseData[0] as TextContent).text),
);
});
});

Expand All @@ -68,7 +71,9 @@ describe('network', () => {
context,
);
const responseData = await response.handle('list_request', context);
t.assert.snapshot?.(stabilizeResponseOutput(responseData[0].text));
t.assert.snapshot?.(
stabilizeResponseOutput((responseData[0] as TextContent).text),
);
});
});

Expand Down Expand Up @@ -106,7 +111,9 @@ describe('network', () => {
context,
);
const responseData = await response.handle('list_request', context);
t.assert.snapshot?.(stabilizeResponseOutput(responseData[0].text));
t.assert.snapshot?.(
stabilizeResponseOutput((responseData[0] as TextContent).text),
);
});
});
});
Expand Down Expand Up @@ -158,7 +165,9 @@ describe('network', () => {
);
const responseData = await response.handle('get_request', context);

t.assert.snapshot?.(stabilizeResponseOutput(responseData[0].text));
t.assert.snapshot?.(
stabilizeResponseOutput((responseData[0] as TextContent).text),
);
});
});
});
Expand Down
Loading