From c8a0ac0fb8dd4e9f930a339551eec4ad0b001138 Mon Sep 17 00:00:00 2001 From: Dzmitry Yahorau Date: Tue, 3 Dec 2024 15:01:53 +0300 Subject: [PATCH 01/11] updated playwright to latest version --- .gitignore | 1 + package.json | 4 ++-- yarn.lock | 43 +++++++++++++++++++++---------------------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 158736b7ba..a6be7c4966 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,7 @@ $RECYCLE.BIN # Build && test /coverage /storybook-static +/test-results /.nyc_output /dist /tsconfig.json diff --git a/package.json b/package.json index 0e57fd0bab..ffc8ad7999 100644 --- a/package.json +++ b/package.json @@ -153,7 +153,7 @@ "webpack-cli": "5.1.4" }, "devDependencies": { - "@playwright/test": "1.32.1", + "@playwright/test": "1.49.0", "@storybook/addon-essentials": "7.0.23", "@storybook/addon-interactions": "7.0.23", "@storybook/addon-links": "7.0.23", @@ -178,7 +178,7 @@ "jest": "29.7.0", "jest-runner-eslint": "2.1.2", "nyc": "15.1.0", - "playwright": "1.32.1", + "playwright": "1.49.0", "react": "18.2.0", "react-dom": "18.2.0", "storybook": "7.0.23", diff --git a/yarn.lock b/yarn.lock index 6d14b0e11a..d4d99d2315 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3007,19 +3007,14 @@ __metadata: languageName: node linkType: hard -"@playwright/test@npm:1.32.1": - version: 1.32.1 - resolution: "@playwright/test@npm:1.32.1" +"@playwright/test@npm:1.49.0": + version: 1.49.0 + resolution: "@playwright/test@npm:1.49.0" dependencies: - "@types/node": "npm:*" - fsevents: "npm:2.3.2" - playwright-core: "npm:1.32.1" - dependenciesMeta: - fsevents: - optional: true + playwright: "npm:1.49.0" bin: playwright: cli.js - checksum: 496236db5867eec9b80a485c3facf926294ab93d2f4fc981fe1518a1534ff09c08fcbe3c02cd70b11c05aa5f27b0ffa32f262c20c94e7f4f375d034e827b56bb + checksum: e87485ab4c02b6dc0bc20a43ea3965c949c45caa4e7f5beea4a0abd29be0a318662931e887072db0d165f8dde93709b97ea1b2c6f4c833b403aa13427d76dd22 languageName: node linkType: hard @@ -5710,7 +5705,7 @@ __metadata: "@babel/preset-env": "npm:7.16.11" "@babel/preset-typescript": "npm:7.16.7" "@config/config": "npm:config@1.31.0" - "@playwright/test": "npm:1.32.1" + "@playwright/test": "npm:1.49.0" "@pzlr/build-core": "npm:2.13.0" "@pzlr/stylus-inheritance": "npm:3.3.0" "@statoscope/webpack-plugin": "npm:5.25.1" @@ -5796,7 +5791,7 @@ __metadata: nyc: "npm:15.1.0" path-equal: "npm:1.1.3" path-to-regexp: "npm:3.2.0" - playwright: "npm:1.32.1" + playwright: "npm:^1.49.0" portfinder: "npm:1.0.28" postcss: "npm:8.4.6" postcss-discard-comments: "npm:6.0.0" @@ -20131,23 +20126,27 @@ __metadata: languageName: node linkType: hard -"playwright-core@npm:1.32.1": - version: 1.32.1 - resolution: "playwright-core@npm:1.32.1" +"playwright-core@npm:1.49.0": + version: 1.49.0 + resolution: "playwright-core@npm:1.49.0" bin: - playwright: cli.js - checksum: 90786f1ef3b82781f151c0f389511e67807d995a055b3200e78d1ce2a1e6d6762b984a5b26a438d7360f21eb54bb0c0f672b55ff244fcc6c654bde644aaced94 + playwright-core: cli.js + checksum: ef9c708293adab100337ed7fd8e61660be381707fc2b84f07b5f40d1ead44feb6a8e52fef98075e594522229d15a9ad56dd1471689cfa59409bec6447c22944d languageName: node linkType: hard -"playwright@npm:1.32.1": - version: 1.32.1 - resolution: "playwright@npm:1.32.1" +"playwright@npm:1.49.0, playwright@npm:^1.49.0": + version: 1.49.0 + resolution: "playwright@npm:1.49.0" dependencies: - playwright-core: "npm:1.32.1" + fsevents: "npm:2.3.2" + playwright-core: "npm:1.49.0" + dependenciesMeta: + fsevents: + optional: true bin: playwright: cli.js - checksum: 34a23bf3c599741bb8aaaf26fe6d2cecb643efdf24cac7867a956eb998a2be83df5a8f91ced562bb04a0de4d78fbefcc5d1d99e24907c6e16dcf7b4e5b3f8638 + checksum: 1fb198d09d388ec46cc2f0fc6b889a8bde8a75066ded82d35f08ba333091ebf3fc4ddf11263a86058a7078c7238ec4f23a86a9f1dc3ebd4f610c9eb07841fb32 languageName: node linkType: hard From 1ff852239545af6bdf2a6034fb2a0efc43df1ead Mon Sep 17 00:00:00 2001 From: Dzmitry Yahorau Date: Tue, 3 Dec 2024 15:14:46 +0300 Subject: [PATCH 02/11] updated lock file --- yarn.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn.lock b/yarn.lock index d4d99d2315..64278eeb1d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5791,7 +5791,7 @@ __metadata: nyc: "npm:15.1.0" path-equal: "npm:1.1.3" path-to-regexp: "npm:3.2.0" - playwright: "npm:^1.49.0" + playwright: "npm:1.49.0" portfinder: "npm:1.0.28" postcss: "npm:8.4.6" postcss-discard-comments: "npm:6.0.0" @@ -20135,7 +20135,7 @@ __metadata: languageName: node linkType: hard -"playwright@npm:1.49.0, playwright@npm:^1.49.0": +"playwright@npm:1.49.0": version: 1.49.0 resolution: "playwright@npm:1.49.0" dependencies: From cf455f60100a48cf95627876a0aa44f1e64cd5a8 Mon Sep 17 00:00:00 2001 From: Dzmitry Yahorau Date: Tue, 3 Dec 2024 16:50:38 +0300 Subject: [PATCH 03/11] fixed type casting --- src/components/pages/p-v4-components-demo/test/api/page.ts | 6 +++--- tests/helpers/utils/index.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/pages/p-v4-components-demo/test/api/page.ts b/src/components/pages/p-v4-components-demo/test/api/page.ts index b13a358dc2..425c26fbbd 100644 --- a/src/components/pages/p-v4-components-demo/test/api/page.ts +++ b/src/components/pages/p-v4-components-demo/test/api/page.ts @@ -6,7 +6,7 @@ * https://github.com/V4Fire/Client/blob/master/LICENSE */ -import type { JSHandle, Page } from 'playwright'; +import type { ElementHandle, JSHandle, Page } from 'playwright'; import { build } from '@config/config'; import { concatURLs } from 'core/url'; @@ -30,7 +30,7 @@ export default class DemoPage { /** * Page component reference. */ - component?: JSHandle; + component?: ElementHandle; /** * Returns the initial page name @@ -65,7 +65,7 @@ export default class DemoPage { await this.page.goto(concatURLs(this.baseUrl, `${this.pageFileName}.html`) + (query.length > 0 ? `?${query}` : ''), {waitUntil: 'networkidle'}); await root.waitFor({state: 'attached'}); - this.component = await root.evaluateHandle((ctx) => ctx.component); + this.component = await root.evaluate((ctx) => (ctx as unknown as DemoPage).component); return this; } diff --git a/tests/helpers/utils/index.ts b/tests/helpers/utils/index.ts index 37f35f8d9e..ed6e1d8d45 100644 --- a/tests/helpers/utils/index.ts +++ b/tests/helpers/utils/index.ts @@ -6,7 +6,7 @@ * https://github.com/V4Fire/Client/blob/master/LICENSE */ -import type { Page, JSHandle } from 'playwright'; +import type { Page, JSHandle, ElementHandle } from 'playwright'; import { evalFn } from 'core/prelude/test-env/components/json'; @@ -96,7 +96,7 @@ export default class Utils { moduleName = `${moduleName}/index.ts`; } - return >>page.evaluateHandle( + return >>page.evaluateHandle( ([{moduleName}]) => globalThis.importModule(moduleName), [{moduleName}] ); } From 35a2d8cec88f371d49411fe0cea9f3083d9dce7c Mon Sep 17 00:00:00 2001 From: Dzmitry Yahorau Date: Tue, 3 Dec 2024 16:57:41 +0300 Subject: [PATCH 04/11] fixed eslint issues --- src/components/pages/p-v4-components-demo/test/api/page.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/pages/p-v4-components-demo/test/api/page.ts b/src/components/pages/p-v4-components-demo/test/api/page.ts index 425c26fbbd..c89979a243 100644 --- a/src/components/pages/p-v4-components-demo/test/api/page.ts +++ b/src/components/pages/p-v4-components-demo/test/api/page.ts @@ -65,7 +65,7 @@ export default class DemoPage { await this.page.goto(concatURLs(this.baseUrl, `${this.pageFileName}.html`) + (query.length > 0 ? `?${query}` : ''), {waitUntil: 'networkidle'}); await root.waitFor({state: 'attached'}); - this.component = await root.evaluate((ctx) => (ctx as unknown as DemoPage).component); + this.component = await root.evaluate((ctx) => (ctx).component); return this; } From 51a000f7b8284c291d091ed0923c3a90a5b36a0a Mon Sep 17 00:00:00 2001 From: kholstinin Date: Wed, 4 Dec 2024 20:08:33 +0500 Subject: [PATCH 05/11] fix: playwright in ci --- .github/workflows/test.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 23b9a33db2..c89591097d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,7 +37,7 @@ jobs: - name: Save build in cache id: cache-build - uses: actions/cache/save@v3 + uses: actions/cache/save@v4 with: path: dist key: cache-${{ github.sha }} @@ -93,7 +93,7 @@ jobs: - name: Restore build from cache id: cache-build - uses: actions/cache/restore@v3 + uses: actions/cache/restore@v4 with: path: dist key: cache-${{ github.sha }} @@ -101,6 +101,9 @@ jobs: - name: Install dependencies run: yarn + - name: Install Playwright Browsers + run: npx playwright install --with-deps + - name: Build tsconfig run: yarn build:tsconfig @@ -129,7 +132,7 @@ jobs: - name: Restore build from cache id: cache-build - uses: actions/cache/restore@v3 + uses: actions/cache/restore@v4 with: path: dist key: cache-${{ github.sha }} From 70bdce560329c61b4ae6d03e45e27281f1d0491f Mon Sep 17 00:00:00 2001 From: Dzmitry Yahorau Date: Sun, 8 Dec 2024 16:25:01 +0300 Subject: [PATCH 06/11] refactor type casting --- .../p-v4-components-demo/test/api/page.ts | 35 +++--- tests/helpers/utils/index.ts | 117 ++++++++++-------- 2 files changed, 82 insertions(+), 70 deletions(-) diff --git a/src/components/pages/p-v4-components-demo/test/api/page.ts b/src/components/pages/p-v4-components-demo/test/api/page.ts index c89979a243..799a74b181 100644 --- a/src/components/pages/p-v4-components-demo/test/api/page.ts +++ b/src/components/pages/p-v4-components-demo/test/api/page.ts @@ -6,14 +6,14 @@ * https://github.com/V4Fire/Client/blob/master/LICENSE */ -import type { ElementHandle, JSHandle, Page } from 'playwright'; -import { build } from '@config/config'; +import type { JSHandle, Page } from "playwright"; +import { build } from "@config/config"; -import { concatURLs } from 'core/url'; -import Component from 'tests/helpers/component'; +import { concatURLs } from "core/url"; +import Component from "tests/helpers/component"; -import type bDummy from 'components/dummies/b-dummy/b-dummy'; -import type pV4ComponentsDemo from 'components/pages/p-v4-components-demo/p-v4-components-demo'; +import type bDummy from "components/dummies/b-dummy/b-dummy"; +import type pV4ComponentsDemo from "components/pages/p-v4-components-demo/p-v4-components-demo"; /** * Page object: provides an API to work with `DemoPage` @@ -30,13 +30,13 @@ export default class DemoPage { /** * Page component reference. */ - component?: ElementHandle; + component?: JSHandle; /** * Returns the initial page name */ get pageName(): string { - return ''; + return ""; } /** @@ -58,14 +58,19 @@ export default class DemoPage { * Opens a demo page * @param [query] - query parameters for the URL, i.e. `a=1&b=1` */ - async goto(query: string = ''): Promise { - const - root = this.page.locator('#root-component'); + async goto(query: string = ""): Promise { + const root = this.page.locator("#root-component"); - await this.page.goto(concatURLs(this.baseUrl, `${this.pageFileName}.html`) + (query.length > 0 ? `?${query}` : ''), {waitUntil: 'networkidle'}); - await root.waitFor({state: 'attached'}); + await this.page.goto( + concatURLs(this.baseUrl, `${this.pageFileName}.html`) + + (query.length > 0 ? `?${query}` : ""), + { waitUntil: "networkidle" } + ); + await root.waitFor({ state: "attached" }); - this.component = await root.evaluate((ctx) => (ctx).component); + this.component = await root.evaluate( + (ctx) => ((ctx)).component + ); return this; } @@ -74,6 +79,6 @@ export default class DemoPage { * Creates a new dummy component */ async createDummy(): Promise> { - return Component.createComponent(this.page, 'b-dummy'); + return Component.createComponent(this.page, "b-dummy"); } } diff --git a/tests/helpers/utils/index.ts b/tests/helpers/utils/index.ts index ed6e1d8d45..deb1b8356f 100644 --- a/tests/helpers/utils/index.ts +++ b/tests/helpers/utils/index.ts @@ -6,15 +6,14 @@ * https://github.com/V4Fire/Client/blob/master/LICENSE */ -import type { Page, JSHandle, ElementHandle } from 'playwright'; +import type { Page, JSHandle, ElementHandle } from "playwright"; -import { evalFn } from 'core/prelude/test-env/components/json'; +import { evalFn } from "core/prelude/test-env/components/json"; -import BOM, { WaitForIdleOptions } from 'tests/helpers/bom'; -import type { ExtractFromJSHandle } from 'tests/helpers/mock'; +import BOM, { WaitForIdleOptions } from "tests/helpers/bom"; +import type { ExtractFromJSHandle } from "tests/helpers/mock"; -const - logsMap = new WeakMap(); +const logsMap = new WeakMap(); // eslint-disable-next-line @typescript-eslint/no-extraneous-class export default class Utils { @@ -34,51 +33,54 @@ export default class Utils { * * @deprecated https://playwright.dev/docs/api/class-page#page-wait-for-function */ - static waitForFunction( + static waitForFunction< + ARGS extends any[] = any[], + CTX extends JSHandle = JSHandle + >( ctx: CTX, fn: (this: any, ctx: ExtractFromJSHandle, ...args: ARGS) => unknown, ...args: ARGS ): Promise { - const - strFn = fn.toString(); - - return ctx.evaluate((ctx, [strFn, ...args]) => { - const - timeout = 4e3, - // eslint-disable-next-line no-new-func - newFn = Function(`return (${strFn}).apply(this, [this, ...${JSON.stringify(args)}])`); - - let - isTimeout = false; - - return new Promise((res, rej) => { - const - timeoutTimer = setTimeout(() => isTimeout = true, timeout); - - const interval = setInterval(() => { - try { - const - fnRes = Boolean(newFn.call(ctx)); - - if (fnRes) { - clearTimeout(timeoutTimer); - clearInterval(interval); - res(); - } - - if (isTimeout) { + const strFn = fn.toString(); + + return ctx.evaluate( + (ctx, [strFn, ...args]) => { + const timeout = 4e3, + // eslint-disable-next-line no-new-func + newFn = Function( + `return (${strFn}).apply(this, [this, ...${JSON.stringify(args)}])` + ); + + let isTimeout = false; + + return new Promise((res, rej) => { + const timeoutTimer = setTimeout(() => (isTimeout = true), timeout); + + const interval = setInterval(() => { + try { + const fnRes = Boolean(newFn.call(ctx)); + + if (fnRes) { + clearTimeout(timeoutTimer); + clearInterval(interval); + res(); + } + + if (isTimeout) { + clearInterval(interval); + rej( + `The given function\n${newFn.toString()}\nreturns a negative result` + ); + } + } catch (err) { clearInterval(interval); - rej(`The given function\n${newFn.toString()}\nreturns a negative result`); + rej(err); } - - } catch (err) { - clearInterval(interval); - rej(err); - } - }, 15); - }); - - }, [strFn, ...args]); + }, 15); + }); + }, + [strFn, ...args] + ); } /** @@ -88,16 +90,19 @@ export default class Utils { * @param moduleName */ static import(page: Page, moduleName: string): Promise> { - if (!moduleName.startsWith('./')) { + if (!moduleName.startsWith("./")) { moduleName = `./src/${moduleName}`; } - if (!moduleName.endsWith('.ts')) { + if (!moduleName.endsWith(".ts")) { moduleName = `${moduleName}/index.ts`; } - return >>page.evaluateHandle( - ([{moduleName}]) => globalThis.importModule(moduleName), [{moduleName}] + return >>( + page.evaluateHandle( + ([{ moduleName }]) => globalThis.importModule(moduleName), + [{ moduleName }] + ) ); } @@ -109,8 +114,11 @@ export default class Utils { * * @deprecated */ - static async reloadAndWaitForIdle(page: Page, idleOptions?: WaitForIdleOptions): Promise { - await page.reload({waitUntil: 'networkidle'}); + static async reloadAndWaitForIdle( + page: Page, + idleOptions?: WaitForIdleOptions + ): Promise { + await page.reload({ waitUntil: "networkidle" }); await BOM.waitForIdleCallback(page, idleOptions); } @@ -127,7 +135,7 @@ export default class Utils { const logsArr = []; logsMap.set(page, logsArr); - page.on('console', (message) => { + page.on("console", (message) => { logsArr.push(message.text()); }); } @@ -146,12 +154,11 @@ export default class Utils { * @param page */ static printPageLogs(page: Page): void { - const - logs = logsMap.get(page); + const logs = logsMap.get(page); if (logs) { // eslint-disable-next-line no-console - console.log(logs.join('\n')); + console.log(logs.join("\n")); logsMap.delete(page); } } From e3642be9334d19ae973a1017500e19039acc5a24 Mon Sep 17 00:00:00 2001 From: Dzmitry Yahorau Date: Sun, 8 Dec 2024 16:31:18 +0300 Subject: [PATCH 07/11] set node v20.11.0 for tests --- .github/workflows/test.yml | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c89591097d..c1c9a8a783 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,7 +24,7 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - cache: 'yarn' + cache: "yarn" - name: Install dependencies run: yarn @@ -42,7 +42,6 @@ jobs: path: dist key: cache-${{ github.sha }} - # Run linters linters: runs-on: ubuntu-latest @@ -57,7 +56,7 @@ jobs: - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v4 with: - cache: 'yarn' + cache: "yarn" node-version: ${{ matrix.node-version }} - name: Install dependencies @@ -69,7 +68,6 @@ jobs: - name: Run tests run: yarn test:linters - # Run playwright tests components: runs-on: ubuntu-latest @@ -78,7 +76,7 @@ jobs: strategy: matrix: - node-version: [20.x] + node-version: ["20.11.0"] shard-index: [1, 2, 3, 4] shard-total: [4] @@ -89,7 +87,7 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - cache: 'yarn' + cache: "yarn" - name: Restore build from cache id: cache-build @@ -110,7 +108,6 @@ jobs: - name: Run components' unit tests run: yarn test:unit --shard=${{ matrix.shard-index }}/${{ matrix.shard-total }} - # Run module tests modules: runs-on: ubuntu-latest @@ -128,14 +125,14 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - cache: 'yarn' + cache: "yarn" - name: Restore build from cache id: cache-build uses: actions/cache/restore@v4 with: - path: dist - key: cache-${{ github.sha }} + path: dist + key: cache-${{ github.sha }} - name: Install dependencies run: yarn From a2d9722c109caabed65e983f9ad7349db390f86b Mon Sep 17 00:00:00 2001 From: Dzmitry Yahorau Date: Sun, 8 Dec 2024 17:35:04 +0300 Subject: [PATCH 08/11] fixed eslint and ts issues --- .../p-v4-components-demo/test/api/page.ts | 33 +++-- tests/helpers/utils/index.ts | 117 ++++++++---------- 2 files changed, 69 insertions(+), 81 deletions(-) diff --git a/src/components/pages/p-v4-components-demo/test/api/page.ts b/src/components/pages/p-v4-components-demo/test/api/page.ts index 799a74b181..8338abbb83 100644 --- a/src/components/pages/p-v4-components-demo/test/api/page.ts +++ b/src/components/pages/p-v4-components-demo/test/api/page.ts @@ -6,14 +6,14 @@ * https://github.com/V4Fire/Client/blob/master/LICENSE */ -import type { JSHandle, Page } from "playwright"; -import { build } from "@config/config"; +import type { JSHandle, Page } from 'playwright'; +import { build } from '@config/config'; -import { concatURLs } from "core/url"; -import Component from "tests/helpers/component"; +import { concatURLs } from 'core/url'; +import Component from 'tests/helpers/component'; -import type bDummy from "components/dummies/b-dummy/b-dummy"; -import type pV4ComponentsDemo from "components/pages/p-v4-components-demo/p-v4-components-demo"; +import type bDummy from 'components/dummies/b-dummy/b-dummy'; +import type pV4ComponentsDemo from 'components/pages/p-v4-components-demo/p-v4-components-demo'; /** * Page object: provides an API to work with `DemoPage` @@ -36,7 +36,7 @@ export default class DemoPage { * Returns the initial page name */ get pageName(): string { - return ""; + return ''; } /** @@ -58,19 +58,14 @@ export default class DemoPage { * Opens a demo page * @param [query] - query parameters for the URL, i.e. `a=1&b=1` */ - async goto(query: string = ""): Promise { - const root = this.page.locator("#root-component"); + async goto(query: string = ''): Promise { + const + root = this.page.locator('#root-component'); - await this.page.goto( - concatURLs(this.baseUrl, `${this.pageFileName}.html`) + - (query.length > 0 ? `?${query}` : ""), - { waitUntil: "networkidle" } - ); - await root.waitFor({ state: "attached" }); + await this.page.goto(concatURLs(this.baseUrl, `${this.pageFileName}.html`) + (query.length > 0 ? `?${query}` : ''), {waitUntil: 'networkidle'}); + await root.waitFor({state: 'attached'}); - this.component = await root.evaluate( - (ctx) => ((ctx)).component - ); + this.component = await root.evaluate((ctx) => (ctx).component); return this; } @@ -79,6 +74,6 @@ export default class DemoPage { * Creates a new dummy component */ async createDummy(): Promise> { - return Component.createComponent(this.page, "b-dummy"); + return Component.createComponent(this.page, 'b-dummy'); } } diff --git a/tests/helpers/utils/index.ts b/tests/helpers/utils/index.ts index deb1b8356f..ed6e1d8d45 100644 --- a/tests/helpers/utils/index.ts +++ b/tests/helpers/utils/index.ts @@ -6,14 +6,15 @@ * https://github.com/V4Fire/Client/blob/master/LICENSE */ -import type { Page, JSHandle, ElementHandle } from "playwright"; +import type { Page, JSHandle, ElementHandle } from 'playwright'; -import { evalFn } from "core/prelude/test-env/components/json"; +import { evalFn } from 'core/prelude/test-env/components/json'; -import BOM, { WaitForIdleOptions } from "tests/helpers/bom"; -import type { ExtractFromJSHandle } from "tests/helpers/mock"; +import BOM, { WaitForIdleOptions } from 'tests/helpers/bom'; +import type { ExtractFromJSHandle } from 'tests/helpers/mock'; -const logsMap = new WeakMap(); +const + logsMap = new WeakMap(); // eslint-disable-next-line @typescript-eslint/no-extraneous-class export default class Utils { @@ -33,54 +34,51 @@ export default class Utils { * * @deprecated https://playwright.dev/docs/api/class-page#page-wait-for-function */ - static waitForFunction< - ARGS extends any[] = any[], - CTX extends JSHandle = JSHandle - >( + static waitForFunction( ctx: CTX, fn: (this: any, ctx: ExtractFromJSHandle, ...args: ARGS) => unknown, ...args: ARGS ): Promise { - const strFn = fn.toString(); - - return ctx.evaluate( - (ctx, [strFn, ...args]) => { - const timeout = 4e3, - // eslint-disable-next-line no-new-func - newFn = Function( - `return (${strFn}).apply(this, [this, ...${JSON.stringify(args)}])` - ); - - let isTimeout = false; - - return new Promise((res, rej) => { - const timeoutTimer = setTimeout(() => (isTimeout = true), timeout); - - const interval = setInterval(() => { - try { - const fnRes = Boolean(newFn.call(ctx)); - - if (fnRes) { - clearTimeout(timeoutTimer); - clearInterval(interval); - res(); - } - - if (isTimeout) { - clearInterval(interval); - rej( - `The given function\n${newFn.toString()}\nreturns a negative result` - ); - } - } catch (err) { + const + strFn = fn.toString(); + + return ctx.evaluate((ctx, [strFn, ...args]) => { + const + timeout = 4e3, + // eslint-disable-next-line no-new-func + newFn = Function(`return (${strFn}).apply(this, [this, ...${JSON.stringify(args)}])`); + + let + isTimeout = false; + + return new Promise((res, rej) => { + const + timeoutTimer = setTimeout(() => isTimeout = true, timeout); + + const interval = setInterval(() => { + try { + const + fnRes = Boolean(newFn.call(ctx)); + + if (fnRes) { + clearTimeout(timeoutTimer); clearInterval(interval); - rej(err); + res(); } - }, 15); - }); - }, - [strFn, ...args] - ); + + if (isTimeout) { + clearInterval(interval); + rej(`The given function\n${newFn.toString()}\nreturns a negative result`); + } + + } catch (err) { + clearInterval(interval); + rej(err); + } + }, 15); + }); + + }, [strFn, ...args]); } /** @@ -90,19 +88,16 @@ export default class Utils { * @param moduleName */ static import(page: Page, moduleName: string): Promise> { - if (!moduleName.startsWith("./")) { + if (!moduleName.startsWith('./')) { moduleName = `./src/${moduleName}`; } - if (!moduleName.endsWith(".ts")) { + if (!moduleName.endsWith('.ts')) { moduleName = `${moduleName}/index.ts`; } - return >>( - page.evaluateHandle( - ([{ moduleName }]) => globalThis.importModule(moduleName), - [{ moduleName }] - ) + return >>page.evaluateHandle( + ([{moduleName}]) => globalThis.importModule(moduleName), [{moduleName}] ); } @@ -114,11 +109,8 @@ export default class Utils { * * @deprecated */ - static async reloadAndWaitForIdle( - page: Page, - idleOptions?: WaitForIdleOptions - ): Promise { - await page.reload({ waitUntil: "networkidle" }); + static async reloadAndWaitForIdle(page: Page, idleOptions?: WaitForIdleOptions): Promise { + await page.reload({waitUntil: 'networkidle'}); await BOM.waitForIdleCallback(page, idleOptions); } @@ -135,7 +127,7 @@ export default class Utils { const logsArr = []; logsMap.set(page, logsArr); - page.on("console", (message) => { + page.on('console', (message) => { logsArr.push(message.text()); }); } @@ -154,11 +146,12 @@ export default class Utils { * @param page */ static printPageLogs(page: Page): void { - const logs = logsMap.get(page); + const + logs = logsMap.get(page); if (logs) { // eslint-disable-next-line no-console - console.log(logs.join("\n")); + console.log(logs.join('\n')); logsMap.delete(page); } } From 69455edff57c9bb0aa2081209d40fc2a440d1bc1 Mon Sep 17 00:00:00 2001 From: Dzmitry Yahorau <48996979+DmitryYegorov@users.noreply.github.com> Date: Sun, 8 Dec 2024 22:07:59 +0300 Subject: [PATCH 09/11] Update test.yml --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c1c9a8a783..f3e7ff04d0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -76,7 +76,7 @@ jobs: strategy: matrix: - node-version: ["20.11.0"] + node-version: [20.x] shard-index: [1, 2, 3, 4] shard-total: [4] From 0368841625b18d8f7f1b9efd7f5ec4184a0945ef Mon Sep 17 00:00:00 2001 From: Dzmitry Yahorau <48996979+DmitryYegorov@users.noreply.github.com> Date: Sun, 8 Dec 2024 23:08:57 +0300 Subject: [PATCH 10/11] Update test.yml --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f3e7ff04d0..12bfea18b3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -76,7 +76,7 @@ jobs: strategy: matrix: - node-version: [20.x] + node-version: [22.x] shard-index: [1, 2, 3, 4] shard-total: [4] From f895586b2b6fd15e93ba1d108ad622d853f5dd17 Mon Sep 17 00:00:00 2001 From: Dzmitry Yahorau <48996979+DmitryYegorov@users.noreply.github.com> Date: Sun, 8 Dec 2024 23:24:13 +0300 Subject: [PATCH 11/11] set nodejs to v20.x --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 12bfea18b3..f3e7ff04d0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -76,7 +76,7 @@ jobs: strategy: matrix: - node-version: [22.x] + node-version: [20.x] shard-index: [1, 2, 3, 4] shard-total: [4]