Skip to content

Commit 99a6abc

Browse files
author
Natallia Harshunova
committed
Use test server for requests
1 parent b0f5253 commit 99a6abc

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

tests/tools/console.test.js.snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ Note that if an opaque response is sufficient, the request's mode can be set to
2525
Learn more:
2626
[Cross-Origin Resource Sharing (\`CORS\`)](https://web.dev/cross-origin-resource-sharing)
2727
### Affected resources
28-
url=https://example.com/data.json data={"corsErrorStatus":{"corsError":"PreflightMissingAllowOriginHeader","failedParameter":""},"isWarning":false,"initiatorOrigin":"","clientSecurityState":{"initiatorIsSecureContext":false,"initiatorIPAddressSpace":"Loopback","privateNetworkRequestPolicy":"BlockFromInsecureToMorePrivate"}}
28+
reqid=1 data={"corsErrorStatus":{"corsError":"PreflightMissingAllowOriginHeader","failedParameter":""},"isWarning":false,"initiatorOrigin":"","clientSecurityState":{"initiatorIsSecureContext":false,"initiatorIPAddressSpace":"Loopback","privateNetworkRequestPolicy":"BlockFromInsecureToMorePrivate"}}
2929
`;

tests/tools/console.test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
getConsoleMessage,
1515
listConsoleMessages,
1616
} from '../../src/tools/console.js';
17+
import {serverHooks} from '../server.js';
1718
import {withBrowser} from '../utils.js';
1819

1920
describe('console', () => {
@@ -152,6 +153,7 @@ describe('console', () => {
152153
});
153154

154155
describe('issues type', () => {
156+
const server = serverHooks();
155157
beforeEach(() => {
156158
setIssuesEnabled(true);
157159
});
@@ -182,30 +184,24 @@ describe('console', () => {
182184
});
183185
});
184186
it('gets issue details with request id parsing', async t => {
187+
server.addRoute('/data.json', (_req, res) => {
188+
res.setHeader('Content-Type', 'application/json');
189+
res.statusCode = 200;
190+
res.end(JSON.stringify({data: 'test data'}));
191+
});
192+
185193
await withBrowser(async (response, context) => {
186194
const page = await context.newPage();
187195
const issuePromise = new Promise<void>(resolve => {
188196
page.once('issue', () => {
189197
resolve();
190198
});
191199
});
192-
await page.setRequestInterception(true);
193-
page.on('request', request => {
194-
if (request.url().includes('example.com')) {
195-
void request.respond({
196-
status: 200,
197-
headers: {
198-
'Content-Type': 'application/json',
199-
},
200-
body: JSON.stringify({}),
201-
});
202-
} else {
203-
void request.continue();
204-
}
205-
});
200+
201+
const url = server.getRoute('/data.json');
206202
await page.setContent(`
207203
<script>
208-
fetch('https://example.com/data.json', {
204+
fetch('${url}', {
209205
method: 'GET',
210206
headers: {
211207
'Content-Type': 'application/json',
@@ -216,7 +212,11 @@ describe('console', () => {
216212
`);
217213
await context.createTextSnapshot();
218214
await issuePromise;
219-
await listConsoleMessages.handler({params: {types: ['issue']}}, response, context);
215+
await listConsoleMessages.handler(
216+
{params: {types: ['issue']}},
217+
response,
218+
context,
219+
);
220220
const response2 = new McpResponse();
221221
await getConsoleMessage.handler(
222222
{params: {msgid: 1}},

0 commit comments

Comments
 (0)