Skip to content

Commit

Permalink
chore(e2e): add E2E_MATCH environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
ma-efremoff committed Jul 26, 2023
1 parent 1030652 commit 5feb050
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 74 deletions.
2 changes: 1 addition & 1 deletion packages/ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 12 additions & 5 deletions packages/ui/src/server/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down
24 changes: 24 additions & 0 deletions packages/ui/tests/e2e/pages/clusters-menu.base.spec.ts
Original file line number Diff line number Diff line change
@@ -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
});
14 changes: 0 additions & 14 deletions packages/ui/tests/e2e/pages/clusters-menu.spec.ts

This file was deleted.

49 changes: 49 additions & 0 deletions packages/ui/tests/e2e/pages/monitoring.spec.ts
Original file line number Diff line number Diff line change
@@ -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"]`,
);
});
24 changes: 0 additions & 24 deletions packages/ui/tests/e2e/pages/operations.spec.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
10 changes: 0 additions & 10 deletions packages/ui/tests/e2e/pages/tablet-cell-bundles.spec.ts

This file was deleted.

21 changes: 18 additions & 3 deletions packages/ui/tests/e2e/utils/index.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand Down
4 changes: 4 additions & 0 deletions packages/ui/tests/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit 5feb050

Please # to comment.