Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
test(heap): run heap leak tests across all browsers (#41069)
Dmitry Gozmancd08dfa6d6dc
diff --git a/tests/config/queryObjects.ts b/tests/config/queryObjects.tsdeleted file mode 100644index 1513e0b8d3..0000000000--- a/tests/config/queryObjects.ts+++ /dev/null@@ -1,42 +0,0 @@-/**- * Copyright (c) Microsoft Corporation.- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */--export async function queryObjectCount(type: Function): Promise<number> {- globalThis.typeForQueryObjects = type;- const session: import('inspector').Session = new (require('node:inspector').Session)();- session.connect();- try {- await new Promise(f => session.post('Runtime.enable', f));- const { result: constructorFunction } = await new Promise(f => session.post('Runtime.evaluate', {- expression: `globalThis.typeForQueryObjects.prototype`,- includeCommandLineAPI: true,- }, (_, result) => f(result))) as any;-- const { objects: instanceArray } = await new Promise(f => session.post('Runtime.queryObjects', {- prototypeObjectId: constructorFunction.objectId- }, (_, result) => f(result))) as any;-- const { result: { value } } = await new Promise<any>(f => session.post('Runtime.callFunctionOn', {- functionDeclaration: 'function (arr) { return this.length; }',- objectId: instanceArray.objectId,- arguments: [{ objectId: instanceArray.objectId }],- }, (_, result) => f(result as any)));-- return value;- } finally {- session.disconnect();- }-}diff --git a/tests/stress/heap.spec.ts b/tests/library/heap.spec.tssimilarity index 77%rename from tests/stress/heap.spec.tsrename to tests/library/heap.spec.tsindex f04e2202e8..ea8f994e80 100644--- a/tests/stress/heap.spec.ts+++ b/tests/library/heap.spec.ts@@ -16,10 +16,38 @@import { contextTest as test, expect } from '../config/browserTest';import { server as coreServer } from '../../packages/playwright-core/lib/coreBundle';-import { queryObjectCount } from '../config/queryObjects';test.describe.configure({ mode: 'serial' });-test.skip(({ browserName }) => browserName !== 'chromium');++// Force a separate worker to start from a clean heap.+test.use({ launchOptions: [async ({ launchOptions }, use) => use(launchOptions), { scope: 'worker' }] });++async function queryObjectCount(type: Function): Promise<number> {+ globalThis.typeForQueryObjects = type;+ const session: import('inspector').Session = new (require('node:inspector').Session)();+ session.connect();+ try {+ await new Promise(f => session.post('Runtime.enable', f));+ const { result: constructorFunction } = await new Promise(f => session.post('Runtime.evaluate', {+ expression: `globalThis.typeForQueryObjects.prototype`,+ includeCommandLineAPI: true,+ }, (_, result) => f(result))) as any;++ const { objects: instanceArray } = await new Promise(f => session.post('Runtime.queryObjects', {+ prototypeObjectId: constructorFunction.objectId+ }, (_, result) => f(result))) as any;++ const { result: { value } } = await new Promise<any>(f => session.post('Runtime.callFunctionOn', {+ functionDeclaration: 'function (arr) { return this.length; }',+ objectId: instanceArray.objectId,+ arguments: [{ objectId: instanceArray.objectId }],+ }, (_, result) => f(result as any)));++ return value;+ } finally {+ session.disconnect();+ }+}const clientClass = {Page: null as Function,@@ -69,9 +97,9 @@ test('should not leak fixtures w/o page', async ({}) => {test('should not leak server-side objects', async ({ page }) => {expect(await queryObjectCount(coreServer.Page)).toBe(1);- // 4 is because v8 heap creates objects for descendant classes, so WKContext, CRContext, FFContext, BidiBrowserContext and our context instance.- expect(await queryObjectCount(coreServer.BrowserContext)).toBe(5);- expect(await queryObjectCount(coreServer.Browser)).toBe(5);+ // 6 is because v8 heap creates objects for descendant classes, so WKContext, CRContext, FFContext, WVBrowserContext, BidiBrowserContext and our context instance.+ expect(await queryObjectCount(coreServer.BrowserContext)).toBe(6);+ expect(await queryObjectCount(coreServer.Browser)).toBe(6);});test('should not leak dispatchers after closing page', async ({ context, server }) => {