diff --git a/.husky/pre-commit b/.husky/pre-commit index ea2476eb902..6b114c6b30e 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -cd tests/e2e && npm run lint && npm run prettier +cd tests/e2e && npm run lint && npm run tsc && npm run prettier diff --git a/tests/e2e/index.ts b/tests/e2e/index.ts index cf50e69b3a3..1f5309042f5 100644 --- a/tests/e2e/index.ts +++ b/tests/e2e/index.ts @@ -47,6 +47,7 @@ export * from './constants/API_TEST_CONSTANTS'; export * from './constants/BASE_TEST_CONSTANTS'; export * from './constants/CHROME_DRIVER_CONSTANTS'; export * from './constants/FACTORY_TEST_CONSTANTS'; +export * from './constants/MOCHA_CONSTANTS'; export * from './constants/MONACO_CONSTANTS'; export * from './constants/OAUTH_CONSTANTS'; export * from './constants/PLUGIN_TEST_CONSTANTS'; diff --git a/tests/e2e/package-lock.json b/tests/e2e/package-lock.json index dfe194182f9..d1922c383d0 100644 --- a/tests/e2e/package-lock.json +++ b/tests/e2e/package-lock.json @@ -1,12 +1,12 @@ { "name": "@eclipse-che/che-e2e", - "version": "7.75.0-SNAPSHOT", + "version": "7.73.0-SNAPSHOT", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@eclipse-che/che-e2e", - "version": "7.75.0-SNAPSHOT", + "version": "7.73.0-SNAPSHOT", "license": "ISC", "dependencies": { "@eclipse-che/api": "latest", @@ -35,6 +35,7 @@ "eslint-plugin-jsdoc": "^46.5.0", "eslint-plugin-prettier": "^5.0.0", "husky": "^8.0.3", + "inversify-inject-decorators": "^3.1.0", "mocha": "^9.1.3", "monaco-page-objects": "3.9.1", "prettier": "^3.0.2", @@ -2699,20 +2700,6 @@ "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "dev": true }, - "node_modules/fsevents": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", - "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" - } - }, "node_modules/function-bind": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", @@ -3067,6 +3054,12 @@ "resolved": "https://registry.npmjs.org/inversify/-/inversify-6.0.1.tgz", "integrity": "sha512-B3ex30927698TJENHR++8FfEaJGqoWOgI6ZY5Ht/nLUsFCwHn6akbwtnUAPCgUepAnTpe2qHxhDNjoKLyz6rgQ==" }, + "node_modules/inversify-inject-decorators": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/inversify-inject-decorators/-/inversify-inject-decorators-3.1.0.tgz", + "integrity": "sha512-/seBlVp5bXrLQS3DpKEmlgeZL6C7Tf/QITd+IMQrbBBGuCbxb7k3hRAWu9XSreNpFzLgSboz3sClLSEmGwHphw==", + "dev": true + }, "node_modules/ip-regex": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ip-regex/-/ip-regex-4.3.0.tgz", diff --git a/tests/e2e/package.json b/tests/e2e/package.json index 100d8ee89ae..12622a140af 100644 --- a/tests/e2e/package.json +++ b/tests/e2e/package.json @@ -38,6 +38,7 @@ "eslint-plugin-header": "^3.1.1", "eslint-plugin-jsdoc": "^46.5.0", "eslint-plugin-prettier": "^5.0.0", + "inversify-inject-decorators": "^3.1.0", "husky": "^8.0.3", "mocha": "^9.1.3", "monaco-page-objects": "3.9.1", diff --git a/tests/e2e/specs/MochaHooks.ts b/tests/e2e/specs/MochaHooks.ts index d13240024f2..995633dce33 100644 --- a/tests/e2e/specs/MochaHooks.ts +++ b/tests/e2e/specs/MochaHooks.ts @@ -77,6 +77,8 @@ exports.mochaHooks = { afterAll: [ async function stopTheDriver(): Promise { if (!BASE_TEST_CONSTANTS.TS_DEBUG_MODE && CHROME_DRIVER_CONSTANTS.TS_USE_WEB_DRIVER_FOR_TEST) { + // ensure that fired events done + await driverHelper.wait(5000); await driverHelper.getDriver().quit(); Logger.info('Chrome driver session stopped.'); } diff --git a/tests/e2e/specs/miscellaneous/CreateWorkspaceWithExistedName.spec.ts b/tests/e2e/specs/miscellaneous/CreateWorkspaceWithExistedName.spec.ts index c9111b9a593..93ff2796788 100644 --- a/tests/e2e/specs/miscellaneous/CreateWorkspaceWithExistedName.spec.ts +++ b/tests/e2e/specs/miscellaneous/CreateWorkspaceWithExistedName.spec.ts @@ -23,7 +23,7 @@ import { FACTORY_TEST_CONSTANTS } from '../../constants/FACTORY_TEST_CONSTANTS'; const stackName: string = BASE_TEST_CONSTANTS.TS_SELENIUM_DASHBOARD_SAMPLE_NAME || 'Python'; const projectName: string = FACTORY_TEST_CONSTANTS.TS_SELENIUM_PROJECT_NAME || 'python-hello-world'; -suite(`"Start workspace with existed workspace name" test`, function (): void { +suite('"Start workspace with existed workspace name" test', function (): void { const workspaceHandlingTests: WorkspaceHandlingTests = e2eContainer.get(CLASSES.WorkspaceHandlingTests); const projectAndFileTests: ProjectAndFileTests = e2eContainer.get(CLASSES.ProjectAndFileTests); const loginTests: LoginTests = e2eContainer.get(CLASSES.LoginTests); @@ -47,11 +47,11 @@ suite(`"Start workspace with existed workspace name" test`, function (): void { expect(isFileImported).not.eqls(undefined); }); - test(`Stop created workspace`, async function (): Promise { + test('Stop created workspace', async function (): Promise { existedWorkspaceName = WorkspaceHandlingTests.getWorkspaceName(); await workspaceHandlingTests.stopWorkspace(existedWorkspaceName); await browserTabsUtil.closeAllTabsExceptCurrent(); - }); + }); test(`Create new workspace from the same ${stackName} stack`, async function (): Promise { existedWorkspaceName = WorkspaceHandlingTests.getWorkspaceName(); diff --git a/tests/e2e/utils/CheReporter.ts b/tests/e2e/utils/CheReporter.ts index f33005b39dc..cc8a6ed6674 100644 --- a/tests/e2e/utils/CheReporter.ts +++ b/tests/e2e/utils/CheReporter.ts @@ -23,21 +23,22 @@ import { CHROME_DRIVER_CONSTANTS } from '../constants/CHROME_DRIVER_CONSTANTS'; import { OAUTH_CONSTANTS } from '../constants/OAUTH_CONSTANTS'; import { REPORTER_CONSTANTS } from '../constants/REPORTER_CONSTANTS'; import { PLUGIN_TEST_CONSTANTS } from '../constants/PLUGIN_TEST_CONSTANTS'; -import { inject, injectable } from 'inversify'; +import { injectable } from 'inversify'; +import getDecorators from 'inversify-inject-decorators'; +import { e2eContainer } from '../configs/inversify.config'; + +const { lazyInject } = getDecorators(e2eContainer); @injectable() class CheReporter extends mocha.reporters.Spec { private static methodIndex: number = 0; private static deleteScreencast: boolean = true; + @lazyInject(CLASSES.DriverHelper) + private readonly driverHelper!: DriverHelper; + @lazyInject(CLASSES.ScreenCatcher) + private readonly screenCatcher!: ScreenCatcher; - constructor( - runner: mocha.Runner, - options: mocha.MochaOptions, - @inject(CLASSES.DriverHelper) - private readonly driverHelper: DriverHelper, - @inject(CLASSES.ScreenCatcher) - private readonly screenCatcher: ScreenCatcher - ) { + constructor(runner: mocha.Runner, options: mocha.MochaOptions) { super(runner, options); runner.on('start', (): void => { @@ -111,13 +112,7 @@ class CheReporter extends mocha.reporters.Spec { } }); - runner.on('end', async (): Promise => { - // ensure that fired events done - await this.driverHelper.wait(5000); - - // close driver - await this.driverHelper.getDriver().quit(); - + runner.on('end', (): void => { // delete screencast folder if conditions matched if (CheReporter.deleteScreencast && REPORTER_CONSTANTS.DELETE_SCREENCAST_IF_TEST_PASS) { rm.sync(REPORTER_CONSTANTS.TS_SELENIUM_REPORT_FOLDER); @@ -158,14 +153,12 @@ class CheReporter extends mocha.reporters.Spec { // take screenshot and write to file const screenshot: string = await this.driverHelper.getDriver().takeScreenshot(); const screenshotStream: WriteStream = fs.createWriteStream(screenshotFileName); - screenshotStream.write(Buffer.from(screenshot, 'base64')); - screenshotStream.end(); + screenshotStream.write(Buffer.from(screenshot, 'base64'), (): void => screenshotStream.end()); // take page source and write to file const pageSource: string = await this.driverHelper.getDriver().getPageSource(); const pageSourceStream: WriteStream = fs.createWriteStream(pageSourceFileName); - pageSourceStream.write(Buffer.from(pageSource)); - pageSourceStream.end(); + pageSourceStream.write(Buffer.from(pageSource), (): void => pageSourceStream.end()); // take browser console logs and write to file const browserLogsEntries: logging.Entry[] = await this.driverHelper.getDriver().manage().logs().get('browser'); @@ -176,8 +169,9 @@ class CheReporter extends mocha.reporters.Spec { }); const browserLogsStream: WriteStream = fs.createWriteStream(browserLogsFileName); - browserLogsStream.write(Buffer.from(browserLogs)); - browserLogsStream.end(); + browserLogsStream.write(Buffer.from(browserLogs), (): void => { + browserLogsStream.end(); + }); }); } }