diff --git a/package-lock.json b/package-lock.json index 1017ebb85..36a0c2b4e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ }, "devDependencies": { "@eslint/js": "^9.35.0", - "@modelcontextprotocol/sdk": "1.20.1", + "@modelcontextprotocol/sdk": "1.20.2", "@rollup/plugin-commonjs": "^28.0.8", "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "^16.0.3", @@ -33,7 +33,7 @@ "eslint-plugin-import": "^2.32.0", "globals": "^16.4.0", "prettier": "^3.6.2", - "puppeteer": "24.26.0", + "puppeteer": "24.26.1", "rollup": "4.52.5", "rollup-plugin-cleanup": "^3.2.1", "rollup-plugin-license": "^3.6.0", @@ -380,9 +380,9 @@ "license": "MIT" }, "node_modules/@modelcontextprotocol/sdk": { - "version": "1.20.1", - "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.20.1.tgz", - "integrity": "sha512-j/P+yuxXfgxb+mW7OEoRCM3G47zCTDqUPivJo/VzpjbG8I9csTXtOprCf5FfOfHK4whOJny0aHuBEON+kS7CCA==", + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.20.2.tgz", + "integrity": "sha512-6rqTdFt67AAAzln3NOKsXRmv5ZzPkgbfaebKBqUbts7vK1GZudqnrun5a8d3M/h955cam9RHZ6Jb4Y1XhnmFPg==", "dev": true, "license": "MIT", "dependencies": { @@ -1976,9 +1976,9 @@ "license": "MIT" }, "node_modules/bare-events": { - "version": "2.8.0", - "resolved": "https://registry.npmjs.org/bare-events/-/bare-events-2.8.0.tgz", - "integrity": "sha512-AOhh6Bg5QmFIXdViHbMc2tLDsBIRxdkIaIddPslJF9Z5De3APBScuqGP2uThXnIpqFrgoxMNC6km7uXNIMLHXA==", + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/bare-events/-/bare-events-2.8.1.tgz", + "integrity": "sha512-oxSAxTS1hRfnyit2CL5QpAOS5ixfBjj6ex3yTNvXyY/kE719jQ/IjuESJBK2w5v4wwQRAHGseVJXx9QBYOtFGQ==", "dev": true, "license": "Apache-2.0", "peerDependencies": { @@ -1991,9 +1991,9 @@ } }, "node_modules/bare-fs": { - "version": "4.4.11", - "resolved": "https://registry.npmjs.org/bare-fs/-/bare-fs-4.4.11.tgz", - "integrity": "sha512-Bejmm9zRMvMTRoHS+2adgmXw1ANZnCNx+B5dgZpGwlP1E3x6Yuxea8RToddHUbWtVV0iUMWqsgZr8+jcgUI2SA==", + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/bare-fs/-/bare-fs-4.5.0.tgz", + "integrity": "sha512-GljgCjeupKZJNetTqxKaQArLK10vpmK28or0+RwWjEl5Rk+/xG3wkpmkv+WrcBm3q1BwHKlnhXzR8O37kcvkXQ==", "dev": true, "license": "Apache-2.0", "optional": true, @@ -5380,9 +5380,9 @@ } }, "node_modules/puppeteer": { - "version": "24.26.0", - "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-24.26.0.tgz", - "integrity": "sha512-5F4A3dGeuw0jJOR3hGV969TO8oi+JG2TzqxAFvH+gxzxh0ILZmiFskWPlhcWQh5s9HAtgZyktOBDqs6zOi7IKA==", + "version": "24.26.1", + "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-24.26.1.tgz", + "integrity": "sha512-3RG2UqclzMFolM2fS4bN8t5/EjZ0VwEoAGVxG8PMGeprjLzj+x0U4auH7MQ4B6ftW+u1JUnTTN8ab4ABPdl4mA==", "dev": true, "hasInstallScript": true, "license": "Apache-2.0", @@ -5391,7 +5391,7 @@ "chromium-bidi": "10.5.1", "cosmiconfig": "^9.0.0", "devtools-protocol": "0.0.1508733", - "puppeteer-core": "24.26.0", + "puppeteer-core": "24.26.1", "typed-query-selector": "^2.12.0" }, "bin": { @@ -5402,9 +5402,9 @@ } }, "node_modules/puppeteer-core": { - "version": "24.26.0", - "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-24.26.0.tgz", - "integrity": "sha512-l3aMYhTdSzazZ14rfpNAPGhnYHsd8mwduqybhu5aO/OR+d24P/V/eo8XTB3GB2yX2ZWf9GLAVcx8nnVPFZpP/A==", + "version": "24.26.1", + "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-24.26.1.tgz", + "integrity": "sha512-YHZdo3chJ5b9pTYVnuDuoI3UX/tWJFJyRZvkLbThGy6XeHWC+0KI8iN0UMCkvde5l/YOk3huiVZ/PvwgSbwdrA==", "dev": true, "license": "Apache-2.0", "dependencies": { diff --git a/package.json b/package.json index 0fdb3a90e..9689137aa 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "mcpName": "io.github.ChromeDevTools/chrome-devtools-mcp", "devDependencies": { "@eslint/js": "^9.35.0", - "@modelcontextprotocol/sdk": "1.20.1", + "@modelcontextprotocol/sdk": "1.20.2", "@rollup/plugin-commonjs": "^28.0.8", "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "^16.0.3", @@ -59,7 +59,7 @@ "eslint-plugin-import": "^2.32.0", "globals": "^16.4.0", "prettier": "^3.6.2", - "puppeteer": "24.26.0", + "puppeteer": "24.26.1", "rollup": "4.52.5", "rollup-plugin-cleanup": "^3.2.1", "rollup-plugin-license": "^3.6.0", diff --git a/tests/McpResponse.test.js.snapshot b/tests/McpResponse.test.js.snapshot new file mode 100644 index 000000000..5f4794985 --- /dev/null +++ b/tests/McpResponse.test.js.snapshot @@ -0,0 +1,45 @@ +exports[`McpResponse > returns correctly formatted snapshot for a simple tree 1`] = ` +# test response +## Page content +uid=1_0 RootWebArea "My test page" url="about:blank" + uid=1_1 button "Click me" focusable focused + uid=1_2 textbox value="Input" + +`; + +exports[`McpResponse > returns values for textboxes 1`] = ` +# test response +## Page content +uid=1_0 RootWebArea "My test page" url="about:blank" + uid=1_1 StaticText "username" + uid=1_2 textbox "username" focusable focused value="mcp" + +`; + +exports[`McpResponse > returns verbose snapshot 1`] = ` +# test response +## Page content +uid=1_0 RootWebArea "My test page" url="about:blank" + uid=1_1 ignored + uid=1_2 ignored + uid=1_3 complementary + uid=1_4 StaticText "test" + uid=1_5 InlineTextBox "test" + +`; + +exports[`McpResponse > saves snapshot to file 1`] = ` +# test response +## Page content +Saved snapshot to +`; + +exports[`McpResponse > saves snapshot to file 2`] = ` +uid=1_0 RootWebArea "My test page" url="about:blank" + uid=1_1 ignored + uid=1_2 ignored + uid=1_3 complementary + uid=1_4 StaticText "test" + uid=1_5 InlineTextBox "test" + +`; diff --git a/tests/McpResponse.test.ts b/tests/McpResponse.test.ts index 1c6678d54..1de5ab863 100644 --- a/tests/McpResponse.test.ts +++ b/tests/McpResponse.test.ts @@ -9,7 +9,13 @@ import {tmpdir} from 'node:os'; import {join} from 'node:path'; import {describe, it} from 'node:test'; -import {getMockRequest, getMockResponse, html, withBrowser} from './utils.js'; +import { + getMockRequest, + getMockResponse, + html, + stabilizeResponseOutput, + withBrowser, +} from './utils.js'; describe('McpResponse', () => { it('list pages', async () => { @@ -51,7 +57,7 @@ Testing 2`, }); }); - it('returns correctly formatted snapshot for a simple tree', async () => { + it('returns correctly formatted snapshot for a simple tree', async t => { await withBrowser(async (response, context) => { const page = context.getSelectedPage(); await page.setContent( @@ -65,19 +71,11 @@ Testing 2`, response.includeSnapshot(); const result = await response.handle('test', context); assert.equal(result[0].type, 'text'); - assert.strictEqual( - result[0].text, - `# test response -## Page content -uid=1_0 RootWebArea "My test page" - uid=1_1 button "Click me" focusable focused - uid=1_2 textbox value="Input" -`, - ); + t.assert.snapshot?.(result[0].text); }); }); - it('returns values for textboxes', async () => { + it('returns values for textboxes', async t => { await withBrowser(async (response, context) => { const page = context.getSelectedPage(); await page.setContent( @@ -91,19 +89,11 @@ uid=1_0 RootWebArea "My test page" response.includeSnapshot(); const result = await response.handle('test', context); assert.equal(result[0].type, 'text'); - assert.strictEqual( - result[0].text, - `# test response -## Page content -uid=1_0 RootWebArea "My test page" - uid=1_1 StaticText "username" - uid=1_2 textbox "username" focusable focused value="mcp" -`, - ); + t.assert.snapshot?.(result[0].text); }); }); - it('returns verbose snapshot', async () => { + it('returns verbose snapshot', async t => { await withBrowser(async (response, context) => { const page = context.getSelectedPage(); await page.setContent(html``); @@ -112,22 +102,11 @@ uid=1_0 RootWebArea "My test page" }); const result = await response.handle('test', context); assert.equal(result[0].type, 'text'); - assert.strictEqual( - result[0].text, - `# test response -## Page content -uid=1_0 RootWebArea "My test page" - uid=1_1 ignored - uid=1_2 ignored - uid=1_3 complementary - uid=1_4 StaticText "test" - uid=1_5 InlineTextBox "test" -`, - ); + t.assert.snapshot?.(result[0].text); }); }); - it('saves snapshot to file', async () => { + it('saves snapshot to file', async t => { const filePath = join(tmpdir(), 'test-screenshot.png'); try { await withBrowser(async (response, context) => { @@ -139,25 +118,10 @@ uid=1_0 RootWebArea "My test page" }); const result = await response.handle('test', context); assert.equal(result[0].type, 'text'); - console.log(result[0].text); - assert.strictEqual( - result[0].text, - `# test response -## Page content -Saved snapshot to ${filePath}.`, - ); + t.assert.snapshot?.(stabilizeResponseOutput(result[0].text)); }); const content = await readFile(filePath, 'utf-8'); - assert.strictEqual( - content, - `uid=1_0 RootWebArea "My test page" - uid=1_1 ignored - uid=1_2 ignored - uid=1_3 complementary - uid=1_4 StaticText "test" - uid=1_5 InlineTextBox "test" -`, - ); + t.assert.snapshot?.(stabilizeResponseOutput(content)); } finally { await rm(filePath, {force: true}); } @@ -492,6 +456,7 @@ No requests found.`, ]; }; const result = await response.handle('test', context); + assert.strictEqual( result[0].text, `# test response diff --git a/tests/utils.ts b/tests/utils.ts index 03cf84f91..6dca14a71 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -170,5 +170,8 @@ export function stabilizeResponseOutput(text: unknown) { // sec-ch-ua-platform:"Linux" const chUaPlatformRegEx = /sec-ch-ua-platform:"[a-zA-Z]*"/g; output = output.replaceAll(chUaPlatformRegEx, 'sec-ch-ua-platform:""'); + + const savedSnapshot = /Saved snapshot to (.*)/g; + output = output.replaceAll(savedSnapshot, 'Saved snapshot to '); return output; }