|
6 | 6 |
|
7 | 7 | import assert from 'node:assert'; |
8 | 8 | import type {IncomingHttpHeaders} from 'node:http'; |
9 | | -import {beforeEach, describe, it} from 'node:test'; |
| 9 | +import {beforeEach, describe, it, mock} from 'node:test'; |
10 | 10 |
|
11 | 11 | import {emulate} from '../../src/tools/emulation.js'; |
12 | 12 | import { |
@@ -209,26 +209,33 @@ describe('emulation', () => { |
209 | 209 | }); |
210 | 210 | }); |
211 | 211 |
|
212 | | - it('scales the default navigation timeout with cpu throttling rate', async () => { |
| 212 | + it('applies cpu throttling to secondary session', async () => { |
213 | 213 | await withMcpContext(async (response, context) => { |
214 | | - const page = context.getSelectedMcpPage(); |
215 | | - let lastNavTimeout: number | undefined; |
216 | | - page.pptrPage.setDefaultNavigationTimeout = (timeout: number) => { |
217 | | - lastNavTimeout = timeout; |
218 | | - }; |
| 214 | + const mcpPage = context.getSelectedMcpPage(); |
| 215 | + const universe = context.getDevToolsUniverse(mcpPage); |
| 216 | + assert.ok(universe); |
| 217 | + |
| 218 | + const sendSpy = mock.method(universe.session, 'send'); |
219 | 219 |
|
220 | 220 | await emulate.handler( |
221 | 221 | { |
222 | 222 | params: { |
223 | 223 | cpuThrottlingRate: 4, |
224 | 224 | }, |
225 | | - page, |
| 225 | + page: mcpPage, |
226 | 226 | }, |
227 | 227 | response, |
228 | 228 | context, |
229 | 229 | ); |
230 | 230 |
|
231 | | - assert.strictEqual(lastNavTimeout, 40000); |
| 231 | + assert.ok(sendSpy.mock.calls.length > 0); |
| 232 | + const cpuCall = sendSpy.mock.calls.find( |
| 233 | + call => call.arguments[0] === 'Emulation.setCPUThrottlingRate', |
| 234 | + ); |
| 235 | + assert.ok(cpuCall); |
| 236 | + assert.deepStrictEqual(cpuCall.arguments[1], {rate: 4}); |
| 237 | + |
| 238 | + sendSpy.mock.restore(); |
232 | 239 | }); |
233 | 240 | }); |
234 | 241 |
|
|
0 commit comments