Skip to content

Commit 5c78734

Browse files
committed
feat: add waitForEventsAfterAction to McpPage
1 parent 3fe3af6 commit 5c78734

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/McpPage.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import type {
1818
TextSnapshot,
1919
TextSnapshotNode,
2020
} from './types.js';
21+
import {
22+
getNetworkMultiplierFromString,
23+
WaitForHelper,
24+
} from './WaitForHelper.js';
2125

2226
/**
2327
* Per-page state wrapper. Consolidates dialog, snapshot, emulation,
@@ -91,6 +95,24 @@ export class McpPage implements ContextPage {
9195
return this.emulationSettings.colorScheme ?? null;
9296
}
9397

98+
createWaitForHelper(
99+
cpuMultiplier: number,
100+
networkMultiplier: number,
101+
): WaitForHelper {
102+
return new WaitForHelper(this.pptrPage, cpuMultiplier, networkMultiplier);
103+
}
104+
105+
waitForEventsAfterAction(
106+
action: () => Promise<unknown>,
107+
options?: {timeout?: number},
108+
): Promise<void> {
109+
const helper = this.createWaitForHelper(
110+
this.cpuThrottlingRate,
111+
getNetworkMultiplierFromString(this.networkConditions),
112+
);
113+
return helper.waitForEventsAfterAction(action, options);
114+
}
115+
94116
dispose(): void {
95117
this.pptrPage.off('dialog', this.#dialogHandler);
96118
}

tests/McpContext.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,13 @@ describe('McpContext', () => {
7575
cpuThrottlingRate: 2,
7676
networkConditions: 'Slow 3G',
7777
});
78-
const stub = sinon.spy(context, 'getWaitForHelper');
78+
const stub = sinon.spy(page, 'createWaitForHelper');
7979

80-
await context.waitForEventsAfterAction(async () => {
80+
await page.waitForEventsAfterAction(async () => {
8181
// trigger the waiting only
8282
});
8383

84-
sinon.assert.calledWithExactly(stub, page.pptrPage, 2, 10);
84+
sinon.assert.calledWithExactly(stub, 2, 10);
8585
});
8686
});
8787

0 commit comments

Comments
 (0)