Skip to content

Commit 756254c

Browse files
Natallia HarshunovaOrKoN
authored andcommitted
update get issue message test snapshotwith id mock, use real id to get message
1 parent 625ce7a commit 756254c

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

tests/tools/console.test.js.snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ uid=1_1 data={"violatingNodeAttribute":"name"}
1414

1515
exports[`console > get_console_message > issues type > gets issue details with request id parsing 1`] = `
1616
# test response
17-
ID: 1
17+
ID: <ID>
1818
Message: issue> Ensure CORS response header values are valid
1919

2020
A cross-origin resource sharing (CORS) request was blocked because of invalid or missing response headers of the request or the associated [preflight request](issueCorsPreflightRequest).

tests/tools/console.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import assert from 'node:assert';
88
import {afterEach, before, beforeEach, describe, it} from 'node:test';
99

10+
import {AggregatedIssue} from '../../node_modules/chrome-devtools-frontend/mcp/mcp.js';
1011
import {setIssuesEnabled} from '../../src/features.js';
1112
import {loadIssueDescriptions} from '../../src/issue-descriptions.js';
1213
import {McpResponse} from '../../src/McpResponse.js';
@@ -212,19 +213,32 @@ describe('console', () => {
212213
`);
213214
await context.createTextSnapshot();
214215
await issuePromise;
216+
const messages = context.getConsoleData();
217+
let issueMsg;
218+
for (const message of messages) {
219+
if (message instanceof AggregatedIssue) {
220+
issueMsg = message;
221+
break;
222+
}
223+
}
224+
assert.ok(issueMsg);
225+
const id = context.getConsoleMessageStableId(issueMsg);
226+
assert.ok(id);
215227
await listConsoleMessages.handler(
216228
{params: {types: ['issue']}},
217229
response,
218230
context,
219231
);
220232
const response2 = new McpResponse();
221233
await getConsoleMessage.handler(
222-
{params: {msgid: 1}},
234+
{params: {msgid: id}},
223235
response2,
224236
context,
225237
);
226238
const formattedResponse = await response2.handle('test', context);
227-
t.assert.snapshot?.(formattedResponse[0].text);
239+
const rawText = formattedResponse[0].text as string;
240+
const sanitizedText = rawText.replaceAll(/ID: \d+/g, 'ID: <ID>');
241+
t.assert.snapshot?.(sanitizedText);
228242
});
229243
});
230244
});

0 commit comments

Comments
 (0)