MM-63669 E2E/Playwright: Move "e2e-tests/playwright/test" to "e2e-tests/playwright" folder (#30647)
* move "e2e-tests/playwright/test" to "e2e-tests/playwright/test" and expose "ensurePluginsLoaded" * add test setup, and expose ensurePluginsLoaded and ensureServerDeployment to pw
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
62753a1481
Коммит
a35a6d7a3a
@@ -4,9 +4,11 @@
|
||||
import os from 'node:os';
|
||||
|
||||
import {expect, test} from '@playwright/test';
|
||||
import {PluginManifest} from '@mattermost/types/plugins';
|
||||
|
||||
import {callsPluginId} from './constant';
|
||||
import {getAdminClient} from './server/init';
|
||||
import {testConfig} from './test_config';
|
||||
|
||||
export async function shouldHaveCallsEnabled(enabled = true) {
|
||||
const {adminClient} = await getAdminClient();
|
||||
@@ -86,3 +88,71 @@ export async function skipIfFeatureFlagNotSet(name: string, value: string | bool
|
||||
|
||||
test.skip(cfg.FeatureFlags[name] !== value, `Skipping test - Feature Flag ${name} needs to be set to ${value}`);
|
||||
}
|
||||
|
||||
// ensureServerDeployment is used to ensure server deployment type is as expected.
|
||||
// If server is not deployed as expected, test will fail.
|
||||
export async function ensureServerDeployment() {
|
||||
const {adminClient} = await getAdminClient();
|
||||
|
||||
// Based on test config, ensure server is on an HA cluster.
|
||||
if (testConfig.haClusterEnabled) {
|
||||
const {haClusterNodeCount, haClusterName} = testConfig;
|
||||
|
||||
const {Enable, ClusterName} = (await adminClient.getConfig()).ClusterSettings;
|
||||
expect(Enable, Enable ? '' : 'Should have cluster enabled').toBe(true);
|
||||
|
||||
const sameClusterName = ClusterName === haClusterName;
|
||||
expect(
|
||||
sameClusterName,
|
||||
sameClusterName
|
||||
? ''
|
||||
: `Should have cluster name set and as expected. Got "${ClusterName}" but expected "${haClusterName}"`,
|
||||
).toBe(true);
|
||||
|
||||
const clusterInfo = await adminClient.getClusterStatus();
|
||||
const sameCount = clusterInfo?.length === haClusterNodeCount;
|
||||
expect(
|
||||
sameCount,
|
||||
sameCount
|
||||
? ''
|
||||
: `Should match number of nodes in a cluster as expected. Got "${clusterInfo?.length}" but expected "${haClusterNodeCount}"`,
|
||||
).toBe(true);
|
||||
|
||||
clusterInfo.forEach((info) =>
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`hostname: ${info.hostname}, version: ${info.version}, config_hash: ${info.config_hash}`),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ensurePluginsLoaded is used to ensure all pluginIds including from testConfig.ensurePluginsInstalled are installed and active.
|
||||
// If any pluginId is not installed, test will fail.
|
||||
// testConfig.ensurePluginsInstalled is derived from `PW_ENSURE_PLUGINS_INSTALLED` environment variable.
|
||||
export async function ensurePluginsLoaded(pluginIds: string[] = []) {
|
||||
const {adminClient} = await getAdminClient();
|
||||
|
||||
const pluginStatus = await adminClient.getPluginStatuses();
|
||||
const plugins = await adminClient.getPlugins();
|
||||
|
||||
// Ensure all plugins are installed and active.
|
||||
testConfig.ensurePluginsInstalled
|
||||
.concat(pluginIds)
|
||||
.filter((pluginId) => Boolean(pluginId))
|
||||
.forEach(async (pluginId) => {
|
||||
const isInstalled = pluginStatus.some((plugin) => plugin.plugin_id === pluginId);
|
||||
|
||||
// If not installed, test will fail.
|
||||
expect(isInstalled, `${pluginId} is not installed. Related test will fail.`).toBe(true);
|
||||
|
||||
const isActive = plugins.active.some((plugin: PluginManifest) => plugin.id === pluginId);
|
||||
if (!isActive) {
|
||||
await adminClient.enablePlugin(pluginId);
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`${pluginId} is installed and has been activated.`);
|
||||
} else {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`${pluginId} is installed and active.`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import {expect} from '@playwright/test';
|
||||
import {Client4} from '@mattermost/client';
|
||||
import {UserProfile} from '@mattermost/types/users';
|
||||
import {PluginManifest} from '@mattermost/types/plugins';
|
||||
@@ -66,14 +65,8 @@ async function sysadminSetup(client: Client4, user: UserProfile | null) {
|
||||
// Set default preferences
|
||||
await savePreferences(client, user?.id ?? '');
|
||||
|
||||
// Ensure all products as plugin are installed and active.
|
||||
await ensurePluginsLoaded(client);
|
||||
|
||||
// Log plugin details
|
||||
await printPluginDetails(client);
|
||||
|
||||
// Ensure server deployment type is as expected
|
||||
await ensureServerDeployment(client);
|
||||
}
|
||||
|
||||
async function printLicenseInfo(client: Client4) {
|
||||
@@ -108,31 +101,6 @@ async function printClientInfo(client: Client4) {
|
||||
- LogSettings.EnableDiagnostics = ${LogSettings?.EnableDiagnostics}`);
|
||||
}
|
||||
|
||||
export async function ensurePluginsLoaded(client: Client4) {
|
||||
const pluginStatus = await client.getPluginStatuses();
|
||||
const plugins = await client.getPlugins();
|
||||
|
||||
testConfig.ensurePluginsInstalled.forEach(async (pluginId) => {
|
||||
const isInstalled = pluginStatus.some((plugin) => plugin.plugin_id === pluginId);
|
||||
if (!isInstalled) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`${pluginId} is not installed. Related visual test will fail.`);
|
||||
return;
|
||||
}
|
||||
|
||||
const isActive = plugins.active.some((plugin: PluginManifest) => plugin.id === pluginId);
|
||||
if (!isActive) {
|
||||
await client.enablePlugin(pluginId);
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`${pluginId} is installed and has been activated.`);
|
||||
} else {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`${pluginId} is installed and active.`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function printPluginDetails(client: Client4) {
|
||||
const plugins = await client.getPlugins();
|
||||
|
||||
@@ -160,37 +128,6 @@ async function printPluginDetails(client: Client4) {
|
||||
console.log('');
|
||||
}
|
||||
|
||||
async function ensureServerDeployment(client: Client4) {
|
||||
if (testConfig.haClusterEnabled) {
|
||||
const {haClusterNodeCount, haClusterName} = testConfig;
|
||||
|
||||
const {Enable, ClusterName} = (await client.getConfig()).ClusterSettings;
|
||||
expect(Enable, Enable ? '' : 'Should have cluster enabled').toBe(true);
|
||||
|
||||
const sameClusterName = ClusterName === haClusterName;
|
||||
expect(
|
||||
sameClusterName,
|
||||
sameClusterName
|
||||
? ''
|
||||
: `Should have cluster name set and as expected. Got "${ClusterName}" but expected "${haClusterName}"`,
|
||||
).toBe(true);
|
||||
|
||||
const clusterInfo = await client.getClusterStatus();
|
||||
const sameCount = clusterInfo?.length === haClusterNodeCount;
|
||||
expect(
|
||||
sameCount,
|
||||
sameCount
|
||||
? ''
|
||||
: `Should match number of nodes in a cluster as expected. Got "${clusterInfo?.length}" but expected "${haClusterNodeCount}"`,
|
||||
).toBe(true);
|
||||
|
||||
clusterInfo.forEach((info) =>
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`hostname: ${info.hostname}, version: ${info.version}, config_hash: ${info.config_hash}`),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function savePreferences(client: Client4, userId: UserProfile['id']) {
|
||||
try {
|
||||
if (!userId) {
|
||||
|
||||
@@ -8,6 +8,8 @@ import {AxeBuilder} from '@axe-core/playwright';
|
||||
import {TestBrowser} from './browser_context';
|
||||
import {
|
||||
ensureLicense,
|
||||
ensurePluginsLoaded,
|
||||
ensureServerDeployment,
|
||||
shouldHaveCallsEnabled,
|
||||
shouldHaveFeatureFlag,
|
||||
shouldRunInLinux,
|
||||
@@ -63,6 +65,7 @@ export class PlaywrightExtended {
|
||||
readonly shouldHaveFeatureFlag;
|
||||
readonly shouldRunInLinux;
|
||||
readonly ensureLicense;
|
||||
readonly ensureServerDeployment;
|
||||
readonly skipIfNoLicense;
|
||||
readonly skipIfFeatureFlagNotSet;
|
||||
|
||||
@@ -71,6 +74,7 @@ export class PlaywrightExtended {
|
||||
readonly getFileFromAsset;
|
||||
|
||||
// ./server
|
||||
readonly ensurePluginsLoaded;
|
||||
readonly getAdminClient;
|
||||
readonly initSetup;
|
||||
|
||||
@@ -111,6 +115,7 @@ export class PlaywrightExtended {
|
||||
this.shouldHaveFeatureFlag = shouldHaveFeatureFlag;
|
||||
this.shouldRunInLinux = shouldRunInLinux;
|
||||
this.ensureLicense = ensureLicense;
|
||||
this.ensureServerDeployment = ensureServerDeployment;
|
||||
this.skipIfNoLicense = skipIfNoLicense;
|
||||
this.skipIfFeatureFlagNotSet = skipIfFeatureFlagNotSet;
|
||||
|
||||
@@ -119,6 +124,7 @@ export class PlaywrightExtended {
|
||||
this.getFileFromAsset = getFileFromAsset;
|
||||
|
||||
// ./server
|
||||
this.ensurePluginsLoaded = ensurePluginsLoaded;
|
||||
this.initSetup = initSetup;
|
||||
this.getAdminClient = getAdminClient;
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user