From 5feb0503aaf9d76ac8f585523d65ee2d225e0bc2 Mon Sep 17 00:00:00 2001 From: Maksim Efremov Date: Tue, 18 Jul 2023 19:30:30 +0300 Subject: [PATCH] chore(e2e): add E2E_MATCH environment variable --- packages/ui/package-lock.json | 2 +- packages/ui/src/server/utils/index.ts | 17 +++++-- ...accounts.spec.ts => accounts.base.spec.ts} | 8 --- .../e2e/pages/clusters-menu.base.spec.ts | 24 +++++++++ .../ui/tests/e2e/pages/clusters-menu.spec.ts | 14 ------ .../ui/tests/e2e/pages/monitoring.spec.ts | 49 +++++++++++++++++++ ...gation.spec.ts => navigation.base.spec.ts} | 0 .../ui/tests/e2e/pages/operations.spec.ts | 24 --------- ...duling.spec.ts => scheduling.base.spec.ts} | 9 ---- .../e2e/pages/tablet-cell-bundles.spec.ts | 10 ---- packages/ui/tests/e2e/utils/index.ts | 21 ++++++-- packages/ui/tests/playwright.config.ts | 4 ++ 12 files changed, 108 insertions(+), 74 deletions(-) rename packages/ui/tests/e2e/pages/{accounts.spec.ts => accounts.base.spec.ts} (90%) create mode 100644 packages/ui/tests/e2e/pages/clusters-menu.base.spec.ts delete mode 100644 packages/ui/tests/e2e/pages/clusters-menu.spec.ts create mode 100644 packages/ui/tests/e2e/pages/monitoring.spec.ts rename packages/ui/tests/e2e/pages/{navigation.spec.ts => navigation.base.spec.ts} (100%) delete mode 100644 packages/ui/tests/e2e/pages/operations.spec.ts rename packages/ui/tests/e2e/pages/{scheduling.spec.ts => scheduling.base.spec.ts} (88%) delete mode 100644 packages/ui/tests/e2e/pages/tablet-cell-bundles.spec.ts diff --git a/packages/ui/package-lock.json b/packages/ui/package-lock.json index fde67cef7..061d8e9e9 100644 --- a/packages/ui/package-lock.json +++ b/packages/ui/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "@ytsaurus/ui", - "version": "0.11.3", + "version": "0.12.0", "dependencies": { "@doc-tools/transform": "3.3.2", "@gravity-ui/app-layout": "1.1.1", diff --git a/packages/ui/src/server/utils/index.ts b/packages/ui/src/server/utils/index.ts index 0c718e8f4..c5c3139ed 100644 --- a/packages/ui/src/server/utils/index.ts +++ b/packages/ui/src/server/utils/index.ts @@ -5,8 +5,7 @@ import {AxiosError, AxiosResponse} from 'axios'; import {AppContext} from '@gravity-ui/nodekit'; import {isYTError} from '../../shared/utils'; import {getApp} from '../ServerFactory'; - -const path = require('path'); +import path from 'path'; export function isProductionEnv() { return getApp().config.appEnv !== 'development'; @@ -21,9 +20,17 @@ export function getInterfaceVersion() { const {INIT_CWD} = process.env; const packageJsonPath = INIT_CWD ? path.resolve(INIT_CWD, 'package.json') - : path.resolve(__dirname, '../../../package.json'); - /* eslint-disable-next-line global-require, security/detect-non-literal-require */ - return require(packageJsonPath).version; + : path.resolve('./package.json'); + try { + /* eslint-disable-next-line global-require, security/detect-non-literal-require */ + return require(packageJsonPath).version; + } catch (e) { + getApp().nodekit.ctx.logError(`Failed to get version from ${packageJsonPath}`, e, { + INIT_CWD, + packageJsonPath, + }); + return 'unkonwn'; + } } else { return 'local'; } diff --git a/packages/ui/tests/e2e/pages/accounts.spec.ts b/packages/ui/tests/e2e/pages/accounts.base.spec.ts similarity index 90% rename from packages/ui/tests/e2e/pages/accounts.spec.ts rename to packages/ui/tests/e2e/pages/accounts.base.spec.ts index 8564e2b4c..0a1275661 100644 --- a/packages/ui/tests/e2e/pages/accounts.spec.ts +++ b/packages/ui/tests/e2e/pages/accounts.base.spec.ts @@ -36,14 +36,6 @@ test('Accounts - General open with filter', async ({page}) => { await expect(page).toHaveURL(makeClusterUrl('accounts/general?account=account-for-e2e')); }); -test('Accounts - Monitoring', async ({page}) => { - await page.goto(makeClusterUrl('accounts/general?account=account-for-e2e')); - - await page.waitForSelector( - `a:text("My monitoring")[href="https://my.monitoring.service/accounts?cluster=${CLUSTER}&account=account-for-e2e"]`, - ); -}); - test('Accounts - Editor', async ({page}) => { await page.goto(makeClusterUrl('accounts/general?account=account-for-e2e')); diff --git a/packages/ui/tests/e2e/pages/clusters-menu.base.spec.ts b/packages/ui/tests/e2e/pages/clusters-menu.base.spec.ts new file mode 100644 index 000000000..76ee3c21b --- /dev/null +++ b/packages/ui/tests/e2e/pages/clusters-menu.base.spec.ts @@ -0,0 +1,24 @@ +import {expect, test} from '@playwright/test'; +import { + CLUSTERS_MENU_EXPECT, + CLUSTER_TITLE, + makeClusterTille, + makeClusterUrl, + makeUrl, +} from '../utils'; + +test('ClustersMenu', async ({page}) => { + await page.goto(makeUrl()); + + const [expectPath = 'navigation?path=/', expectTitle = 'Navigation', expectTitlePath = '/'] = ( + CLUSTERS_MENU_EXPECT || 'navigation?path=/' + ).split(';'); + + // Expect a title "to contain" a substring. + await expect(page).toHaveTitle('Clusters'); + + await page.click(`.cluster-menu__item-heading:text("${CLUSTER_TITLE?.toUpperCase()}")`); + + await expect(page).toHaveTitle(makeClusterTille({page: expectTitle, path: expectTitlePath})); + await expect(page).toHaveURL(makeClusterUrl(expectPath)); // checks default users settings, Navigation is default start page +}); diff --git a/packages/ui/tests/e2e/pages/clusters-menu.spec.ts b/packages/ui/tests/e2e/pages/clusters-menu.spec.ts deleted file mode 100644 index 4961ef14d..000000000 --- a/packages/ui/tests/e2e/pages/clusters-menu.spec.ts +++ /dev/null @@ -1,14 +0,0 @@ -import {test, expect} from '@playwright/test'; -import {CLUSTER_TITLE, makeClusterTille, makeClusterUrl, makeUrl} from '../utils'; - -test('ClustersMenu', async ({page}) => { - await page.goto(makeUrl()); - - // Expect a title "to contain" a substring. - await expect(page).toHaveTitle('Clusters'); - - await page.click(`.cluster-menu__item-heading:text("${CLUSTER_TITLE?.toUpperCase()}")`); - - await expect(page).toHaveTitle(makeClusterTille({page: 'Navigation', path: '/'})); - await expect(page).toHaveURL(makeClusterUrl('navigation?path=/')); // checks default users settings, Navigation is default start page -}); diff --git a/packages/ui/tests/e2e/pages/monitoring.spec.ts b/packages/ui/tests/e2e/pages/monitoring.spec.ts new file mode 100644 index 000000000..c1054036a --- /dev/null +++ b/packages/ui/tests/e2e/pages/monitoring.spec.ts @@ -0,0 +1,49 @@ +import {expect, test} from '@playwright/test'; +import {CLUSTER, E2E_OPERATION_ID, E2E_OPERATION_2_ID, makeClusterUrl} from '../utils'; + +test('Accounts - Monitoring', async ({page}) => { + await page.goto(makeClusterUrl('accounts/general?account=account-for-e2e')); + + await page.waitForSelector( + `a:text("My monitoring")[href="https://my.monitoring.service/accounts?cluster=${CLUSTER}&account=account-for-e2e"]`, + ); +}); + +test('Scheduling - Monitoring', async ({page}) => { + await page.goto(makeClusterUrl('scheduling/overview?pool=yt-e2e-pool-1&tree=default')); + + await page.waitForSelector('text="yt-e2e-pool-1"'); + await page.waitForSelector( + `a:text("My monitoring")[href="https://monitoring-service.my-domain.com/d/DB-id?var-pool=yt-e2e-pool-1&var-cluster=${CLUSTER}&var-tree=default"]`, + ); +}); + +test('Operations - Monitoring for one pool', async ({page}) => { + await page.goto(makeClusterUrl(`operations/${E2E_OPERATION_ID}`)); + + await page.waitForSelector( + `a:text("My monitoring")[href^="https://my.monitoring.service/operations?cluster=${CLUSTER}&id=${E2E_OPERATION_ID}&pool=root&tree=default&from="]`, + ); +}); + +test('Operations - Monitoring two pools ', async ({page}) => { + await page.goto(makeClusterUrl(`operations/${E2E_OPERATION_2_ID}`)); + + await page.click('.tabs :text("Monitoring")'); + + await page.waitForSelector( + `a:text("My monitoring")[href^="https://my.monitoring.service/operations?cluster=${CLUSTER}&id=${E2E_OPERATION_2_ID}&pool=root&tree=default&from="]`, + ); + + await page.waitForSelector( + `a:text("My monitoring")[href^="https://my.monitoring.service/operations?cluster=${CLUSTER}&id=${E2E_OPERATION_2_ID}&pool=test-e2e&tree=e2e&from="]`, + ); +}); + +test('Tablet Cell Bundles - Monitoring', async ({page}) => { + await page.goto(makeClusterUrl('tablet_cell_bundles/tablet_cells?activeBundle=default')); + + await page.waitForSelector( + `a:text("My monitoring")[href="https://my.monitoring.service/bundles?cluster=${CLUSTER}&bundle=default"]`, + ); +}); diff --git a/packages/ui/tests/e2e/pages/navigation.spec.ts b/packages/ui/tests/e2e/pages/navigation.base.spec.ts similarity index 100% rename from packages/ui/tests/e2e/pages/navigation.spec.ts rename to packages/ui/tests/e2e/pages/navigation.base.spec.ts diff --git a/packages/ui/tests/e2e/pages/operations.spec.ts b/packages/ui/tests/e2e/pages/operations.spec.ts deleted file mode 100644 index 842a03a4f..000000000 --- a/packages/ui/tests/e2e/pages/operations.spec.ts +++ /dev/null @@ -1,24 +0,0 @@ -import {test} from '@playwright/test'; -import {CLUSTER, E2E_OPERATION_ID, E2E_OPERATION_2_ID, makeClusterUrl} from '../utils'; - -test('Operations - Monitoring for one pool', async ({page}) => { - await page.goto(makeClusterUrl(`operations/${E2E_OPERATION_ID}`)); - - await page.waitForSelector( - `a:text("My monitoring")[href^="https://my.monitoring.service/operations?cluster=${CLUSTER}&id=${E2E_OPERATION_ID}&pool=root&tree=default&from="]`, - ); -}); - -test('Operations - Monitoring two pools ', async ({page}) => { - await page.goto(makeClusterUrl(`operations/${E2E_OPERATION_2_ID}`)); - - await page.click('.tabs :text("Monitoring")'); - - await page.waitForSelector( - `a:text("My monitoring")[href^="https://my.monitoring.service/operations?cluster=${CLUSTER}&id=${E2E_OPERATION_2_ID}&pool=root&tree=default&from="]`, - ); - - await page.waitForSelector( - `a:text("My monitoring")[href^="https://my.monitoring.service/operations?cluster=${CLUSTER}&id=${E2E_OPERATION_2_ID}&pool=test-e2e&tree=e2e&from="]`, - ); -}); diff --git a/packages/ui/tests/e2e/pages/scheduling.spec.ts b/packages/ui/tests/e2e/pages/scheduling.base.spec.ts similarity index 88% rename from packages/ui/tests/e2e/pages/scheduling.spec.ts rename to packages/ui/tests/e2e/pages/scheduling.base.spec.ts index 34b3af032..31bab7882 100644 --- a/packages/ui/tests/e2e/pages/scheduling.spec.ts +++ b/packages/ui/tests/e2e/pages/scheduling.base.spec.ts @@ -59,15 +59,6 @@ test('Scheduliing - Details', async ({page}) => { expect(rowCount2).toBe(1); }); -test('Scheduling - Monitoring', async ({page}) => { - await page.goto(makeClusterUrl('scheduling/overview?pool=yt-e2e-pool-1&tree=default')); - - await page.waitForSelector('text="yt-e2e-pool-1"'); - await page.waitForSelector( - `a:text("My monitoring")[href="https://monitoring-service.my-domain.com/d/DB-id?var-pool=yt-e2e-pool-1&var-cluster=${CLUSTER}&var-tree=default"]`, - ); -}); - test('Scheduling - Pool - Edit Dialog - Change Weight', async ({page}) => { await page.goto(makeClusterUrl('scheduling/overview?pool=yt-e2e-pool-1&tree=default')); const editBtn = await page.getByTitle('edit pool yt-e2e-pool-1'); diff --git a/packages/ui/tests/e2e/pages/tablet-cell-bundles.spec.ts b/packages/ui/tests/e2e/pages/tablet-cell-bundles.spec.ts deleted file mode 100644 index a839db807..000000000 --- a/packages/ui/tests/e2e/pages/tablet-cell-bundles.spec.ts +++ /dev/null @@ -1,10 +0,0 @@ -import {test} from '@playwright/test'; -import {CLUSTER, makeClusterUrl} from '../utils'; - -test('Tablet Cell Bundles - Monitoring', async ({page}) => { - await page.goto(makeClusterUrl('tablet_cell_bundles/tablet_cells?activeBundle=default')); - - await page.waitForSelector( - `a:text("My monitoring")[href="https://my.monitoring.service/bundles?cluster=${CLUSTER}&bundle=default"]`, - ); -}); diff --git a/packages/ui/tests/e2e/utils/index.ts b/packages/ui/tests/e2e/utils/index.ts index ede6e6eb8..7d97447d2 100644 --- a/packages/ui/tests/e2e/utils/index.ts +++ b/packages/ui/tests/e2e/utils/index.ts @@ -1,9 +1,24 @@ import './afterEach'; -export const {BASE_URL, CLUSTER, E2E_DIR, E2E_OPERATION_ID, E2E_OPERATION_2_ID, CLUSTER_TITLE} = - process.env; +export const { + BASE_URL, + CLUSTER, + E2E_DIR, + E2E_OPERATION_ID, + E2E_OPERATION_2_ID, + CLUSTER_TITLE, + CLUSTERS_MENU_EXPECT, +} = process.env; -console.log({BASE_URL, CLUSTER, CLUSTER_TITLE, E2E_DIR, E2E_OPERATION_ID, E2E_OPERATION_2_ID}); +console.log({ + BASE_URL, + CLUSTER, + CLUSTER_TITLE, + E2E_DIR, + E2E_OPERATION_ID, + E2E_OPERATION_2_ID, + CLUSTERS_MENU_EXPECT, +}); if (!CLUSTER || !E2E_DIR) { throw new Error('E2E environment is not prepared'); diff --git a/packages/ui/tests/playwright.config.ts b/packages/ui/tests/playwright.config.ts index 346a5bc06..d8df14f93 100644 --- a/packages/ui/tests/playwright.config.ts +++ b/packages/ui/tests/playwright.config.ts @@ -8,11 +8,15 @@ import {defineConfig, devices} from '@playwright/test'; const headless = process.env.HEADLESS !== 'false'; +const {E2E_MATCH = '.spec.'} = process.env; +const testMatch = new RegExp(E2E_MATCH.replace(/\./g, '.')); + /** * See https://playwright.dev/docs/test-configuration. */ export default defineConfig({ testDir: './e2e', + testMatch, /* Run tests in files in parallel */ fullyParallel: headless, /* Fail the build on CI if you accidentally left test.only in the source code. */