Chrome DevTools for coding agents
test: use snapshots for McpResponse (#483)
Nikolay Vitkovb30bdd6e1741
diff --git a/tests/McpResponse.test.js.snapshot b/tests/McpResponse.test.js.snapshotindex 5f479498..79d43b8f 100644--- a/tests/McpResponse.test.js.snapshot+++ b/tests/McpResponse.test.js.snapshot@@ -1,3 +1,91 @@+exports[`McpResponse > add network request when attached 1`] = `+# test response+## Request http://example.com+Status: [pending]+### Request Headers+- content-size:10+## Network requests+Showing 1-1 of 1 (Page 1 of 1).+reqid=1 GET http://example.com [pending]+`;++exports[`McpResponse > add network request when attached with POST data 1`] = `+# test response+## Request http://example.com+Status: [success - 200]+### Request Headers+- content-size:10+### Request Body+{"request":"body"}+### Response Headers+- Content-Type:application/json+### Response Body+{"response":"body"}+## Network requests+Showing 1-1 of 1 (Page 1 of 1).+reqid=1 POST http://example.com [success - 200]+`;++exports[`McpResponse > add network requests when setting is true 1`] = `+# test response+## Network requests+Showing 1-2 of 2 (Page 1 of 1).+reqid=1 GET http://example.com [pending]+reqid=2 GET http://example.com [pending]+`;++exports[`McpResponse > adds a message when no console messages exist 1`] = `+# test response+## Console messages+<no console messages found>+`;++exports[`McpResponse > adds a prompt dialog 1`] = `+# test response+# Open dialog+prompt: message (default value: "default").+Call handle_dialog to handle it before continuing.+`;++exports[`McpResponse > adds an alert dialog 1`] = `+# test response+# Open dialog+alert: message.+Call handle_dialog to handle it before continuing.+`;++exports[`McpResponse > adds console messages when the setting is true 1`] = `+# test response+## Console messages+Showing 1-1 of 1 (Page 1 of 1).+msgid=1 [log] Hello from the test (1 args)+`;++exports[`McpResponse > adds cpu throttling setting when it is over 1 1`] = `+# test response+## CPU emulation+Emulating: 4x slowdown+`;++exports[`McpResponse > adds throttling setting when it is not null 1`] = `+# test response+## Network emulation+Emulating: Slow 3G+Default navigation timeout set to 100000 ms+`;++exports[`McpResponse > allows response text lines to be added 1`] = `+# test response+Testing 1+Testing 2+`;++exports[`McpResponse > list pages 1`] = `+# test response+## Pages+0: about:blank [selected]+`;+exports[`McpResponse > returns correctly formatted snapshot for a simple tree 1`] = `# test response## Page content@@ -43,3 +131,46 @@ uid=1_0 RootWebArea "My test page" url="about:blank"uid=1_5 InlineTextBox "test"`;++exports[`McpResponse network request filtering > filters network requests by resource type 1`] = `+# test response+## Network requests+Showing 1-2 of 2 (Page 1 of 1).+reqid=1 GET http://example.com [pending]+reqid=1 GET http://example.com [pending]+`;++exports[`McpResponse network request filtering > filters network requests by single resource type 1`] = `+# test response+## Network requests+Showing 1-1 of 1 (Page 1 of 1).+reqid=1 GET http://example.com [pending]+`;++exports[`McpResponse network request filtering > shows all requests when empty resourceTypes array is provided 1`] = `+# test response+## Network requests+Showing 1-5 of 5 (Page 1 of 1).+reqid=1 GET http://example.com [pending]+reqid=1 GET http://example.com [pending]+reqid=1 GET http://example.com [pending]+reqid=1 GET http://example.com [pending]+reqid=1 GET http://example.com [pending]+`;++exports[`McpResponse network request filtering > shows all requests when no filters are provided 1`] = `+# test response+## Network requests+Showing 1-5 of 5 (Page 1 of 1).+reqid=1 GET http://example.com [pending]+reqid=1 GET http://example.com [pending]+reqid=1 GET http://example.com [pending]+reqid=1 GET http://example.com [pending]+reqid=1 GET http://example.com [pending]+`;++exports[`McpResponse network request filtering > shows no requests when filter matches nothing 1`] = `+# test response+## Network requests+No requests found.+`;diff --git a/tests/McpResponse.test.ts b/tests/McpResponse.test.tsindex 1de5ab86..4cf52252 100644--- a/tests/McpResponse.test.ts+++ b/tests/McpResponse.test.ts@@ -18,32 +18,22 @@ import {} from './utils.js';describe('McpResponse', () => {- it('list pages', async () => {+ it('list pages', async t => {await withBrowser(async (response, context) => {response.setIncludePages(true);const result = await response.handle('test', context);assert.equal(result[0].type, 'text');- assert.deepStrictEqual(- result[0].text,- `# test response-## Pages-0: about:blank [selected]`,- );+ t.assert.snapshot?.(result[0].text);});});- it('allows response text lines to be added', async () => {+ it('allows response text lines to be added', async t => {await withBrowser(async (response, context) => {response.appendResponseLine('Testing 1');response.appendResponseLine('Testing 2');const result = await response.handle('test', context);assert.equal(result[0].type, 'text');- assert.deepStrictEqual(- result[0].text,- `# test response-Testing 1-Testing 2`,- );+ t.assert.snapshot?.(result[0].text);});});@@ -127,18 +117,12 @@ Testing 2`,}});- it('adds throttling setting when it is not null', async () => {+ it('adds throttling setting when it is not null', async t => {await withBrowser(async (response, context) => {context.setNetworkConditions('Slow 3G');const result = await response.handle('test', context);assert.equal(result[0].type, 'text');- assert.strictEqual(- result[0].text,- `# test response-## Network emulation-Emulating: Slow 3G-Default navigation timeout set to 100000 ms`,- );+ t.assert.snapshot?.(result[0].text);});});@@ -161,16 +145,11 @@ Default navigation timeout set to 100000 ms`,});});- it('adds cpu throttling setting when it is over 1', async () => {+ 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);- assert.strictEqual(- result[0].text,- `# test response-## CPU emulation-Emulating: 4x slowdown`,- );+ t.assert.snapshot?.(result[0].text);});});@@ -182,7 +161,7 @@ Emulating: 4x slowdown`,});});- it('adds a prompt dialog', async () => {+ it('adds a prompt dialog', async t => {await withBrowser(async (response, context) => {const page = context.getSelectedPage();const dialogPromise = new Promise<void>(resolve => {@@ -196,17 +175,11 @@ Emulating: 4x slowdown`,await dialogPromise;const result = await response.handle('test', context);await context.getDialog()?.dismiss();- assert.strictEqual(- result[0].text,- `# test response-# Open dialog-prompt: message (default value: "default").-Call handle_dialog to handle it before continuing.`,- );+ t.assert.snapshot?.(result[0].text);});});- it('adds an alert dialog', async () => {+ it('adds an alert dialog', async t => {await withBrowser(async (response, context) => {const page = context.getSelectedPage();const dialogPromise = new Promise<void>(resolve => {@@ -220,31 +193,18 @@ Call handle_dialog to handle it before continuing.`,await dialogPromise;const result = await response.handle('test', context);await context.getDialog()?.dismiss();- assert.strictEqual(- result[0].text,- `# test response-# Open dialog-alert: message.-Call handle_dialog to handle it before continuing.`,- );+ t.assert.snapshot?.(result[0].text);});});- it('add network requests when setting is true', async () => {+ it('add network requests when setting is true', async t => {await withBrowser(async (response, context) => {response.setIncludeNetworkRequests(true);context.getNetworkRequests = () => {return [getMockRequest({stableId: 1}), getMockRequest({stableId: 2})];};const result = await response.handle('test', context);- assert.strictEqual(- result[0].text,- `# test response-## Network requests-Showing 1-2 of 2 (Page 1 of 1).-reqid=1 GET http://example.com [pending]-reqid=2 GET http://example.com [pending]`,- );+ t.assert.snapshot?.(result[0].text);});});@@ -259,7 +219,7 @@ reqid=2 GET http://example.com [pending]`,});});- it('add network request when attached with POST data', async () => {+ it('add network request when attached with POST data', async t => {await withBrowser(async (response, context) => {response.setIncludeNetworkRequests(true);const httpResponse = getMockResponse();@@ -287,27 +247,11 @@ reqid=2 GET http://example.com [pending]`,const result = await response.handle('test', context);- assert.strictEqual(- result[0].text,- `# test response-## Request http://example.com-Status: [success - 200]-### Request Headers-- content-size:10-### Request Body-${JSON.stringify({request: 'body'})}-### Response Headers-- Content-Type:application/json-### Response Body-${JSON.stringify({response: 'body'})}-## Network requests-Showing 1-1 of 1 (Page 1 of 1).-reqid=1 POST http://example.com [success - 200]`,- );+ t.assert.snapshot?.(result[0].text);});});- it('add network request when attached', async () => {+ it('add network request when attached', async t => {await withBrowser(async (response, context) => {response.setIncludeNetworkRequests(true);const request = getMockRequest();@@ -319,21 +263,11 @@ reqid=1 POST http://example.com [success - 200]`,};response.attachNetworkRequest(1);const result = await response.handle('test', context);- assert.strictEqual(- result[0].text,- `# test response-## Request http://example.com-Status: [pending]-### Request Headers-- content-size:10-## Network requests-Showing 1-1 of 1 (Page 1 of 1).-reqid=1 GET http://example.com [pending]`,- );+ t.assert.snapshot?.(result[0].text);});});- it('adds console messages when the setting is true', async () => {+ it('adds console messages when the setting is true', async t => {await withBrowser(async (response, context) => {response.setIncludeConsoleData(true);const page = context.getSelectedPage();@@ -348,32 +282,22 @@ reqid=1 GET http://example.com [pending]`,await consoleMessagePromise;const result = await response.handle('test', context);assert.ok(result[0].text);- // Cannot check the full text because it contains local file path- assert.ok(- result[0].text.toString().startsWith(`# test response-## Console messages`),- );- assert.ok(result[0].text.toString().includes('Hello from the test'));+ t.assert.snapshot?.(result[0].text);});});- it('adds a message when no console messages exist', async () => {+ 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);- assert.strictEqual(- result[0].text.toString(),- `# test response-## Console messages-<no console messages found>`,- );+ t.assert.snapshot?.(result[0].text);});});});describe('McpResponse network request filtering', () => {- it('filters network requests by resource type', async () => {+ it('filters network requests by resource type', async t => {await withBrowser(async (response, context) => {response.setIncludeNetworkRequests(true, {resourceTypes: ['script', 'stylesheet'],@@ -387,18 +311,11 @@ describe('McpResponse network request filtering', () => {];};const result = await response.handle('test', context);- assert.strictEqual(- result[0].text,- `# test response-## Network requests-Showing 1-2 of 2 (Page 1 of 1).-reqid=1 GET http://example.com [pending]-reqid=1 GET http://example.com [pending]`,- );+ t.assert.snapshot?.(result[0].text);});});- it('filters network requests by single resource type', async () => {+ it('filters network requests by single resource type', async t => {await withBrowser(async (response, context) => {response.setIncludeNetworkRequests(true, {resourceTypes: ['image'],@@ -411,17 +328,11 @@ reqid=1 GET http://example.com [pending]`,];};const result = await response.handle('test', context);- assert.strictEqual(- result[0].text,- `# test response-## Network requests-Showing 1-1 of 1 (Page 1 of 1).-reqid=1 GET http://example.com [pending]`,- );+ t.assert.snapshot?.(result[0].text);});});- it('shows no requests when filter matches nothing', async () => {+ it('shows no requests when filter matches nothing', async t => {await withBrowser(async (response, context) => {response.setIncludeNetworkRequests(true, {resourceTypes: ['font'],@@ -434,16 +345,11 @@ reqid=1 GET http://example.com [pending]`,];};const result = await response.handle('test', context);- assert.strictEqual(- result[0].text,- `# test response-## Network requests-No requests found.`,- );+ t.assert.snapshot?.(result[0].text);});});- it('shows all requests when no filters are provided', async () => {+ it('shows all requests when no filters are provided', async t => {await withBrowser(async (response, context) => {response.setIncludeNetworkRequests(true);context.getNetworkRequests = () => {@@ -457,21 +363,11 @@ No requests found.`,};const result = await response.handle('test', context);- assert.strictEqual(- result[0].text,- `# test response-## Network requests-Showing 1-5 of 5 (Page 1 of 1).-reqid=1 GET http://example.com [pending]-reqid=1 GET http://example.com [pending]-reqid=1 GET http://example.com [pending]-reqid=1 GET http://example.com [pending]-reqid=1 GET http://example.com [pending]`,- );+ t.assert.snapshot?.(result[0].text);});});- it('shows all requests when empty resourceTypes array is provided', async () => {+ it('shows all requests when empty resourceTypes array is provided', async t => {await withBrowser(async (response, context) => {response.setIncludeNetworkRequests(true, {resourceTypes: [],@@ -486,17 +382,7 @@ reqid=1 GET http://example.com [pending]`,];};const result = await response.handle('test', context);- assert.strictEqual(- result[0].text,- `# test response-## Network requests-Showing 1-5 of 5 (Page 1 of 1).-reqid=1 GET http://example.com [pending]-reqid=1 GET http://example.com [pending]-reqid=1 GET http://example.com [pending]-reqid=1 GET http://example.com [pending]-reqid=1 GET http://example.com [pending]`,- );+ t.assert.snapshot?.(result[0].text);});});});