From 34388e6c4b2a6615ea68bc508de888fd63a8810c Mon Sep 17 00:00:00 2001 From: Khadreal Date: Fri, 3 Jan 2025 14:26:01 +0100 Subject: [PATCH] Refactor script and command, revert config modifications --- config/wp.config.sample.ts | 8 +--- package.json | 4 +- report.ts | 75 +++++--------------------------------- 3 files changed, 14 insertions(+), 73 deletions(-) diff --git a/config/wp.config.sample.ts b/config/wp.config.sample.ts index 3295372..8331c6f 100755 --- a/config/wp.config.sample.ts +++ b/config/wp.config.sample.ts @@ -29,7 +29,6 @@ const WP_ADMIN_USER = { * WP_SSH_ADDRESS: string; * WP_SSH_KEY: string; * WP_SSH_ROOT_DIR: string; - * ENVIRONMENT_USERNAME: string; * }} */ const { @@ -43,8 +42,7 @@ const { WP_SSH_USERNAME = '', WP_SSH_ADDRESS = '', WP_SSH_KEY = '', - WP_SSH_ROOT_DIR = '', - ENVIRONMENT_USERNAME = '' + WP_SSH_ROOT_DIR = '' } = process.env; /** @@ -81,7 +79,6 @@ const { * noJsLlcss: string; * elementorLlcss: string; * }, - * ENVIRONMENT_USERNAME: string; * }} */ export { @@ -95,6 +92,5 @@ export { WP_SSH_USERNAME, WP_SSH_ADDRESS, WP_SSH_KEY, - WP_SSH_ROOT_DIR, - ENVIRONMENT_USERNAME + WP_SSH_ROOT_DIR }; \ No newline at end of file diff --git a/package.json b/package.json index 03addab..d00bdb0 100755 --- a/package.json +++ b/package.json @@ -10,8 +10,8 @@ "scripts": { "lint": "eslint . --ext .ts", "lint:fix": "eslint . --ext .ts --fix", - "test:e2e": "$npm_package_config_testCommand && npm run push-report --tag=e2e", - "test:smoke": "$npm_package_config_testCommand --tags @smoke && npm run push-report --tag=smoke", + "test:e2e": "$npm_package_config_testCommand && npm run push-report --tag=$npm_config_tag", + "test:smoke": "$npm_package_config_testCommand --tags @smoke && npm run push-report --tag=$npm_config_tag", "test:local": "$npm_package_config_testCommand --tags @local", "test:online": "$npm_package_config_testCommand --tags @online", "test:vr": "$npm_package_config_testCommand --tags @vr", diff --git a/report.ts b/report.ts index 716e9ae..b0665cb 100644 --- a/report.ts +++ b/report.ts @@ -1,36 +1,15 @@ import path from "path"; import {promises as fs} from "fs"; -import {ENVIRONMENT_USERNAME} from "./config/wp.config"; - -interface MoveReportOptions { - destinationDir?: string; - newName?: string; -} - -/** - * Generates a default name using timestamp and username - * - * @returns string Generated name in format "YYYYMMDD_HHMMSS_username" - */ -async function generateDefaultName() : Promise { - const timestamp = new Date().toISOString() - .replace(/[-:]/g, '') - .replace(/T/, '_') - .replace(/\..+/, ''); - - const username = ENVIRONMENT_USERNAME || 'unknown'; - return `${timestamp}_${username}`; -} /** * Moves test results to a destination directory with optional renaming * - * @param options Configuration options for moving the report + * @param {string} testTag Tag name of the report generated. * @returns Promise Path where the folder was moved to */ -export async function moveTestReport(options: MoveReportOptions = {}): Promise { +export async function moveTestReport(testTag: string): Promise { const SOURCE_FOLDER = 'test-results'; - const DEFAULT_DESTINATION = '/var/shared/rocket-e2e-reports'; + const destinationDir = '/var/shared/rocket-e2e-reports'; // Validate source folder exists try { @@ -39,9 +18,6 @@ export async function moveTestReport(options: MoveReportOptions = {}): Promise { +(async (): Promise => { try { - const destination = process.argv[2]; const tag = process.env.npm_config_tag; - const options: MoveReportOptions = { - destinationDir: destination, - newName: tag ? `${tag}_test` : undefined - }; - - const newPath = await moveTestReport(options); - console.log(`Folder successfully moved to '${newPath}'`); - } catch (error) { - console.error(`Error: ${error.message}`); - process.exit(1); - } -} - -/** - * Get the script path and arguments for moving the report. - * - * @return MoveReportOptions - */ -async function initialization(): Promise { - const destination = process.argv[2]; - const tag = process.env.npm_config_tag; - - return { - destinationDir: destination, - newName: tag ? `${tag}_test` : undefined - }; -} + //If tag is not provided, then the report shouldn't be moved or renamed. + if(! tag) { + process.exit(1); + } -(async (): Promise => { - try { - const options = await initialization(); - await moveTestReport(options); + await moveTestReport(tag); } catch (err) { console.error(`Failed to execute the script: ${err.message}`); process.exit(1);