Skip to content

Commit

Permalink
feat: added test suits
Browse files Browse the repository at this point in the history
Signed-off-by: mdolhalo <[email protected]>
  • Loading branch information
mdolhalo committed Oct 6, 2023
1 parent 0811b7e commit 6768afd
Show file tree
Hide file tree
Showing 43 changed files with 597 additions and 118 deletions.
8 changes: 1 addition & 7 deletions tests/e2e/configs/inversify.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
**********************************************************************/

import 'reflect-metadata';
import { Container, decorate, injectable, unmanaged } from 'inversify';
import { Container } from 'inversify';
import { IDriver } from '../driver/IDriver';
import { ChromeDriver } from '../driver/ChromeDriver';
import { CLASSES, EXTERNAL_CLASSES, TYPES } from './inversify.types';
Expand Down Expand Up @@ -52,12 +52,6 @@ import { Main as Generator } from '@eclipse-che/che-devworkspace-generator/lib/m
import { ContainerTerminal, KubernetesCommandLineToolsExecutor } from '../utils/KubernetesCommandLineToolsExecutor';
import { ShellExecutor } from '../utils/ShellExecutor';

decorate(injectable(), Generator);
decorate(injectable(), LocatorLoader);
decorate(unmanaged(), LocatorLoader, 0);
decorate(unmanaged(), LocatorLoader, 1);
decorate(unmanaged(), LocatorLoader, 2);

const e2eContainer: Container = new Container({ defaultScope: 'Transient', skipBaseClassChecks: true });

e2eContainer.bind<IDriver>(TYPES.Driver).to(ChromeDriver).inSingletonScope();
Expand Down
12 changes: 8 additions & 4 deletions tests/e2e/configs/mocharc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,31 @@
'use strict';

import { MOCHA_CONSTANTS } from '../constants/MOCHA_CONSTANTS';
import { BASE_TEST_CONSTANTS } from '../constants/BASE_TEST_CONSTANTS';

/**
* full available options list https://mochajs.org/api/mocha
*/

module.exports = {
timeout: MOCHA_CONSTANTS.MOCHA_DEFAULT_TIMEOUT,
slow: 60000,
reporter: 'mocha-multi-reporters',
reporterOptions: 'configFile=configs/reporters-config.json',
ui: 'tdd',
require: ['dist/specs/MochaHooks.js', 'ts-node/register'],
bail: MOCHA_CONSTANTS.MOCHA_BAIL,
'full-trace': true,
spec:
// variable MOCHA_DIRECTORY uses in command "test-all-devfiles" and sets up automatically.
// you can set it up to run files from specific directory with export environmental variable.
MOCHA_CONSTANTS.MOCHA_DIRECTORY
BASE_TEST_CONSTANTS.TEST_ENVIRONMENT !== ''
? `dist/suits/${BASE_TEST_CONSTANTS.ARCH_VERSION}/${BASE_TEST_CONSTANTS.OCP_VERSION}/${MOCHA_CONSTANTS.MOCHA_SUITE}.suite.js`
: // variable MOCHA_DIRECTORY uses in command "test-all-devfiles" and sets up automatically.
// you can set it up to run files from specific directory with export environmental variable.
MOCHA_CONSTANTS.MOCHA_DIRECTORY
? // to run one file (name without extension). uses in "test", "test-all-devfiles".
MOCHA_CONSTANTS.MOCHA_USERSTORY
? `dist/specs/${MOCHA_CONSTANTS.MOCHA_DIRECTORY}/${MOCHA_CONSTANTS.MOCHA_USERSTORY}.spec.js`
: `dist/specs/${MOCHA_CONSTANTS.MOCHA_DIRECTORY}/**.spec.js`
: `dist/specs/${process.env.MOCHA_DIRECTORY}/**.spec.js`
: MOCHA_CONSTANTS.MOCHA_USERSTORY
? [`dist/specs/**/${MOCHA_CONSTANTS.MOCHA_USERSTORY}.spec.js`, `dist/specs/${MOCHA_CONSTANTS.MOCHA_USERSTORY}.spec.js`]
: ['dist/specs/**/**.spec.js', 'dist/specs/**.spec.js'],
Expand Down
58 changes: 58 additions & 0 deletions tests/e2e/configs/sh-scripts/regressionTestRun.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
# shellcheck source=/dev/null

export ARCH_VERSION="x86_64"

########################################
############# Methods ##################
########################################

launchAPITests() {
export MOCHA_SUITE="APITest"
echo "MOCHA_SUITE = ${MOCHA_SUITE}"
npm run driver-less-test
}

launchDynamicAPITests() {
export MOCHA_SUITE="DynamicAPITest"
echo "MOCHA_SUITE = ${MOCHA_SUITE}"
npm run delayed-test
}

launchUITests() {
export MOCHA_SUITE="UITest"
echo "MOCHA_SUITE = ${MOCHA_SUITE}"
npm run test
}

launchAllTests() {
echo ""
echo "Launching all tests for $ARCH_VERSION $OCP_VERSION"
echo ""
launchDynamicAPITests
launchAPITests
launchUITests
}

########################################
############# Launching ################
########################################

#possible values OCP_VERSION="airgap-ocp-413", "ocp4-12"
export OCP_VERSION="ocp4-13"
echo "suits/$ARCH_VERSION/$OCP_VERSION/$MOCHA_SUITE"
echo "$(<"suits/$ARCH_VERSION/$OCP_VERSION/InitEnvironmental.sh")"
source "suits/$ARCH_VERSION/$OCP_VERSION/InitEnvironmental.sh" &&
launchAllTests

export OCP_VERSION="ocp4-12"
echo "suits/$ARCH_VERSION/$OCP_VERSION/$MOCHA_SUITE"
echo "$(<"suits/$ARCH_VERSION/$OCP_VERSION/InitEnvironmental.sh")"
source "suits/$ARCH_VERSION/$OCP_VERSION/InitEnvironmental.sh" &&
launchAllTests

export OCP_VERSION="airgap-ocp-413"
echo "suits/$ARCH_VERSION/$OCP_VERSION/$MOCHA_SUITE"
echo "$(<"suits/$ARCH_VERSION/$OCP_VERSION/InitEnvironmental.sh")"
source "suits/$ARCH_VERSION/$OCP_VERSION/InitEnvironmental.sh" &&
launchAllTests
7 changes: 5 additions & 2 deletions tests/e2e/constants/API_TEST_CONSTANTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const SUPPORTED_DEVFILE_REGISTRIES: {
GIT_HUB_CHE_DEVFILE_REGISTRY_URL: 'https://api.github.com/repos/eclipse-che/che-devfile-registry/contents/devfiles/'
};
export const API_TEST_CONSTANTS: {
TS_API_TEST_DEV_WORKSPACE_LIST: string | undefined;
TS_API_TEST_KUBERNETES_COMMAND_LINE_TOOL: string;
TS_API_TEST_PLUGIN_REGISTRY_URL: string | undefined;
TS_API_TEST_CHE_CODE_EDITOR_DEVFILE_URI: string | undefined;
Expand Down Expand Up @@ -62,6 +63,8 @@ export const API_TEST_CONSTANTS: {
* to run all devfile from registry. used in DevfileAcceptanceTestAPI.suite.ts
*/
TS_API_ACCEPTANCE_TEST_REGISTRY_URL(): string {
return process.env.TS_API_ACCEPTANCE_TEST_REGISTRY_URL || SUPPORTED_DEVFILE_REGISTRIES.INBUILT_APPLICATION_DEVFILE_REGISTRY_URL();
}
return process.env.TS_API_ACCEPTANCE_TEST_REGISTRY_URL || '';
},

TS_API_TEST_DEV_WORKSPACE_LIST: process.env.TS_API_TEST_DEV_WORKSPACE_LIST || undefined
};
18 changes: 18 additions & 0 deletions tests/e2e/constants/BASE_TEST_CONSTANTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export enum Platform {
}

export const BASE_TEST_CONSTANTS: {
OCP_VERSION: string;
ARCH_VERSION: string;
TEST_ENVIRONMENT: string;
IS_PRODUCT_DOCUMENTATION_RELEASED: any;
TESTING_APPLICATION_VERSION: string;
TS_DEBUG_MODE: boolean;
Expand All @@ -33,6 +36,21 @@ export const BASE_TEST_CONSTANTS: {
*/
TS_SELENIUM_BASE_URL: !process.env.TS_SELENIUM_BASE_URL ? 'http://sample-url' : process.env.TS_SELENIUM_BASE_URL.replace(/\/$/, ''),

/**
* system arch type
*/
ARCH_VERSION: process.env.ARCH_VERSION || '',

/**
* openShift version
*/
OCP_VERSION: process.env.OCP_VERSION || '',

/**
* test environment (used as prefix in suite name)
*/
TEST_ENVIRONMENT: process.env.TEST_ENVIRONMENT || '',

/**
* testing application version
*/
Expand Down
11 changes: 9 additions & 2 deletions tests/e2e/constants/MOCHA_CONSTANTS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
import { BASE_TEST_CONSTANTS } from './BASE_TEST_CONSTANTS';

export const MOCHA_CONSTANTS: {
MOCHA_SUITE: string | undefined;
MOCHA_DELAYED_SUITE: boolean;
MOCHA_DEFAULT_TIMEOUT: string | number;
MOCHA_DIRECTORY: string | undefined;
MOCHA_USERSTORY: undefined | string;
Expand All @@ -21,7 +24,11 @@ export const MOCHA_CONSTANTS: {

MOCHA_BAIL: process.env.MOCHA_BAIL !== 'false',

MOCHA_DEFAULT_TIMEOUT: process.env.MOCHA_DEFAULT_TIMEOUT || 1200000,
MOCHA_DELAYED_SUITE: process.env.MOCHA_DELAYED_SUITE === 'true',

MOCHA_RETRIES: process.env.MOCHA_RETRIES || 3
MOCHA_DEFAULT_TIMEOUT: process.env.MOCHA_DEFAULT_TIMEOUT || 420000,

MOCHA_RETRIES: process.env.MOCHA_RETRIES || BASE_TEST_CONSTANTS.TEST_ENVIRONMENT === '' ? 0 : 2,

MOCHA_SUITE: process.env.MOCHA_SUITE || undefined
};
2 changes: 2 additions & 0 deletions tests/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
"tsc": "rm -rf ./dist && ./configs/sh-scripts/generateIndex.sh && tsc -p .",
"test": "./configs/sh-scripts/initDefaultValues.sh npm run lint && npm run tsc && export USERSTORY=$USERSTORY && mocha --config dist/configs/mocharc.js",
"driver-less-test": "export TS_USE_WEB_DRIVER_FOR_TEST=false && npm run test",
"delayed-test": "npm run lint && npm run tsc && export TS_USE_WEB_DRIVER_FOR_TEST=false && export MOCHA_DELAYED_SUITE=true && mocha --config dist/configs/mocharc.js --delay",
"open-allure-dasboard": "allure generate .allure-results --clean -o .allure-report && allure open .allure-report",
"cleanup-docker": "if [ $(docker ps -a | grep -c selenium-e2e) -gt 0 ]; then docker rm -f $(docker ps --filter \"name=selenium-e2e\" -aq); fi;",
"test-docker": "npm run cleanup-docker && docker run -it --shm-size=2g -p 5920:5920 --name selenium-e2e -e TS_SELENIUM_BASE_URL=$TS_SELENIUM_BASE_URL eclipse/che-e2e:nightly",
"test-docker-mount-e2e": "npm run cleanup-docker && docker run -it --shm-size=2g -p 5920:5920 --name selenium-e2e -e TS_SELENIUM_BASE_URL=$TS_SELENIUM_BASE_URL -v $(pwd):/tmp/e2e:Z eclipse/che-e2e:nightly",
"test-all-devfiles": " ./configs/sh-scripts/initDefaultValues.sh && ./configs/sh-scripts/initDevfileTests.sh",
"test-regression": "./configs/sh-scripts/regressionTestRun.sh",
"devfile-acceptance-test-suite": "./configs/sh-scripts/initDefaultValues.sh npm run lint && npm run tsc && export TS_USE_WEB_DRIVER_FOR_TEST=false && mocha 'dist/specs/api/*.js' --config dist/configs/mocharc.js --delay --grep 'Devfile acceptance test suite'"
},
"author": "Ihor Okhrimenko ([email protected])",
Expand Down
11 changes: 11 additions & 0 deletions tests/e2e/specs/MochaHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { allure } from 'allure-mocha/runtime';
import { BASE_TEST_CONSTANTS } from '../constants/BASE_TEST_CONSTANTS';
import { MONACO_CONSTANTS } from '../constants/MONACO_CONSTANTS';
import { CHROME_DRIVER_CONSTANTS } from '../constants/CHROME_DRIVER_CONSTANTS';
import { decorate, injectable, unmanaged } from 'inversify';
import { Main } from '@eclipse-che/che-devworkspace-generator/lib/main';
import { LocatorLoader } from 'monaco-page-objects/out/locators/loader';

const driverHelper: DriverHelper = e2eContainer.get(CLASSES.DriverHelper);
let latestWorkspace: string = '';
Expand All @@ -34,6 +37,14 @@ export function registerRunningWorkspace(workspaceName: string): void {

exports.mochaHooks = {
beforeAll: [
function decorateExternalClasses(): void {
decorate(injectable(), Main);
decorate(injectable(), LocatorLoader);
decorate(unmanaged(), LocatorLoader, 0);
decorate(unmanaged(), LocatorLoader, 1);
decorate(unmanaged(), LocatorLoader, 2);
},

function enableRequestInterceptor(): void {
if (BASE_TEST_CONSTANTS.TS_SELENIUM_REQUEST_INTERCEPTOR) {
CheApiRequestHandler.enableRequestInterceptor();
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/specs/api/ContainerOverridesAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ import { expect } from 'chai';
import { ShellExecutor } from '../../utils/ShellExecutor';
import { e2eContainer } from '../../configs/inversify.config';
import { CLASSES } from '../../configs/inversify.types';
import { BASE_TEST_CONSTANTS } from '../../constants/BASE_TEST_CONSTANTS';

suite('Test defining container overrides via attribute.', function (): void {
suite(`Test defining container overrides via attribute ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void {
const pathToSampleFile: string = path.resolve('resources/container-overrides.yaml');
const workspaceName: string = YAML.parse(fs.readFileSync(pathToSampleFile, 'utf8')).metadata.name;
const kubernetesCommandLineToolsExecutor: KubernetesCommandLineToolsExecutor = e2eContainer.get(
Expand Down
18 changes: 10 additions & 8 deletions tests/e2e/specs/api/DevfileAcceptanceTestAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@ import { StringUtil } from '../../utils/StringUtil';
import { Logger } from '../../utils/Logger';
import { e2eContainer } from '../../configs/inversify.config';
import { CLASSES } from '../../configs/inversify.types';
import { DevfilesRegistryHelper } from '../../utils/DevfilesRegistryHelper';
import { MOCHA_CONSTANTS } from '../../constants/MOCHA_CONSTANTS';
import { API_TEST_CONSTANTS } from '../../constants/API_TEST_CONSTANTS';

/**
* dynamically generating tests
* info: https://mochajs.org/#delayed-root-suite
*/
// todo: skipped while don`t use to avoid sending useless requests
// eslint-disable-next-line @typescript-eslint/require-await
void (async function (): Promise<void> {
// const devfilesRegistryHelper: DevfilesRegistryHelper = e2eContainer.get(CLASSES.DevfilesRegistryHelper);

const devfileSamples: any = [];
// devfileSamples = await devfilesRegistryHelper.collectPathsToDevfilesFromRegistry();
const devfilesRegistryHelper: DevfilesRegistryHelper = e2eContainer.get(CLASSES.DevfilesRegistryHelper);

let devfileSamples: any = [];
if (MOCHA_CONSTANTS.MOCHA_DELAYED_SUITE && API_TEST_CONSTANTS.TS_API_ACCEPTANCE_TEST_REGISTRY_URL()) {
devfileSamples = await devfilesRegistryHelper.collectPathsToDevfilesFromRegistry(false);
}
for (const devfileSample of devfileSamples) {
suite.skip(`Devfile acceptance test suite for ${devfileSample.name}`, function (): void {
suite(`Devfile acceptance test suite for ${devfileSample.name}`, function (): void {
this.bail(false);
this.timeout(1500000); // 25 minutes because build of Quarkus sample takes 20+ minutes
let devWorkspaceConfigurationHelper: DevWorkspaceConfigurationHelper;
Expand Down Expand Up @@ -105,7 +107,7 @@ void (async function (): Promise<void> {
);
Logger.info(`Full build command to be executed: ${commandString}`);

const output: ShellString = containerTerminal.executeCommand(commandString, command.exec.component);
const output: ShellString = containerTerminal.execInContainerCommand(commandString, command.exec.component);
expect(output.code).eqls(0);
});
}
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/specs/api/EmptyWorkspaceAPI.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ suite('Empty workspace API test', function (): void {

const gitRepository: string = 'https://github.com/crw-qe/web-nodejs-sample';

suiteSetup('Create empty workspace with OC client', async function (): Promise<void> {
suiteSetup(`Create empty workspace with OC client ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, async function (): Promise<void> {
const workspaceName: string = 'empty-' + Math.floor(Math.random() * 1000);
const devfileContent: string = 'schemaVersion: 2.2.0\n' + 'metadata:\n' + ` name: ${workspaceName}\n`;

Expand All @@ -54,7 +54,7 @@ suite('Empty workspace API test', function (): void {
expect(output.stdout).contains('condition met');
});

suite('Clone public repo without previous setup', function (): void {
suite(`Clone public repo without previous setup ${BASE_TEST_CONSTANTS.TEST_ENVIRONMENT}`, function (): void {
test('Check if public repo can be cloned', function (): void {
containerWorkDir = containerTerminal.pwd().stdout.replace('\n', '');
const cloneOutput: ShellString = containerTerminal.gitClone(gitRepository);
Expand Down
Loading

0 comments on commit 6768afd

Please sign in to comment.