Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

test(memory): update getMetrics function to use CDPSession instead of Page

白熱931418d5db95
diff --git a/e2e/memory/memory.spec.ts b/e2e/memory/memory.spec.ts
index 0d57f772a8..4d2c969248 100644
--- a/e2e/memory/memory.spec.ts
+++ b/e2e/memory/memory.spec.ts
@@ -129,27 +129,27 @@ test('memory', async ({ page }) => {
await page.goto('http://localhost:3000/sheets/');
await page.waitForTimeout(5000);
- const memoryAfterFirstInstance = (await getMetrics(page)).JSHeapUsedSize;
+ const memoryAfterFirstInstance = (await getMetrics(client)).JSHeapUsedSize;
await page.evaluate(() => window.E2EControllerAPI.loadAndRelease(1));
await page.waitForTimeout(5000);
- const memoryAfterFirstLoad = (await getMetrics(page)).JSHeapUsedSize;
+ const memoryAfterFirstLoad = (await getMetrics(client)).JSHeapUsedSize;
await page.evaluate(() => window.E2EControllerAPI.loadAndRelease(2));
await page.waitForTimeout(5000);
- const memoryAfterSecondLoad = (await getMetrics(page)).JSHeapUsedSize;
+ const memoryAfterSecondLoad = (await getMetrics(client)).JSHeapUsedSize;
const unitMemoryOverflow = memoryAfterSecondLoad - memoryAfterFirstLoad;
await reportToPosthog('unit_memory_overflow', { value: unitMemoryOverflow });
await page.evaluate(() => window.univer.dispose());
await page.waitForTimeout(5000);
await takeHeapSnapshot(client, 'memory-first.heapsnapshot');
- const memoryAfterDisposingFirstInstance = (await getMetrics(page)).JSHeapUsedSize;
+ const memoryAfterDisposingFirstInstance = (await getMetrics(client)).JSHeapUsedSize;
await page.evaluate(() => window.createNewInstance());
await page.waitForTimeout(5000);
await page.evaluate(() => window.univer.dispose());
await page.waitForTimeout(5000);
await takeHeapSnapshot(client, 'memory-second.heapsnapshot');
- const memoryAfterDisposingSecondUniver = (await getMetrics(page)).JSHeapUsedSize;
+ const memoryAfterDisposingSecondUniver = (await getMetrics(client)).JSHeapUsedSize;
const instanceMemoryOverflow = memoryAfterDisposingSecondUniver - memoryAfterDisposingFirstInstance;
const univerMemoryOverflow = memoryAfterDisposingSecondUniver - memoryAfterFirstInstance;
await reportToPosthog('instance_memory_overflow', { value: instanceMemoryOverflow });
diff --git a/e2e/memory/util.ts b/e2e/memory/util.ts
index 2836e16f32..5413be287e 100644
--- a/e2e/memory/util.ts
+++ b/e2e/memory/util.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { Page } from '@playwright/test';
+import type { CDPSession, Page } from '@playwright/test';
interface IMetrics {
JSHeapUsedSize: number;
@@ -27,8 +27,7 @@ interface IMetrics {
* @return {IMetrics}
* @see {@link https://github.com/microsoft/playwright/issues/18071}
*/
-export async function getMetrics(page: Page): Promise<IMetrics> {
- const client = await page.context().newCDPSession(page);
+export async function getMetrics(client: CDPSession): Promise<IMetrics> {
await client.send('Performance.enable');
await client.send('HeapProfiler.collectGarbage');
const perfMetricObject = await client.send('Performance.getMetrics');