Skip to content

Commit 2805245

Browse files
committed
Guard JSON.parse with isError check in BiDi tests
Prevents confusing SyntaxError if a tool returns an error message instead of JSON. Now fails with a clear assertion showing the actual error text.
1 parent 7e9dbc1 commit 2805245

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

test/bidi.test.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe('BiDi Diagnostic Tools', () => {
5151
await new Promise(r => setTimeout(r, 500));
5252

5353
const result = await client.callTool('get_console_logs', {});
54+
assert.ok(!result.isError, `Tool returned error: ${getResponseText(result)}`);
5455
const logs = JSON.parse(getResponseText(result));
5556

5657
assert.ok(logs.find(l => l.text?.includes('Hello from console')), 'Should capture console.log');
@@ -94,6 +95,7 @@ describe('BiDi Diagnostic Tools', () => {
9495
});
9596
await new Promise(r => setTimeout(r, 1000));
9697
const result = await client.callTool('get_page_errors', {});
98+
assert.ok(!result.isError, `Tool returned error: ${getResponseText(result)}`);
9799
const text = getResponseText(result);
98100
const errors = JSON.parse(text);
99101
const jsError = errors.find(e => e.text?.includes('Intentional test error'));
@@ -124,6 +126,7 @@ describe('BiDi Diagnostic Tools', () => {
124126
await new Promise(r => setTimeout(r, 1000));
125127

126128
const result = await client.callTool('get_network_logs', {});
129+
assert.ok(!result.isError, `Tool returned error: ${getResponseText(result)}`);
127130
const logs = JSON.parse(getResponseText(result));
128131

129132
const pageLoad = logs.find(l => l.url?.includes('bidi.html'));

0 commit comments

Comments
 (0)