From 8741f7d7b554b0987c571aeadf2e0413175cacf4 Mon Sep 17 00:00:00 2001 From: Gael Robin Date: Fri, 29 Mar 2024 05:13:50 +0100 Subject: [PATCH] Replace check if debug.log exists by ssh --- src/support/steps/general.ts | 14 +++++++++----- utils/commands.ts | 23 ++++++++++++++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/support/steps/general.ts b/src/support/steps/general.ts index 89fd6e4..3106a04 100644 --- a/src/support/steps/general.ts +++ b/src/support/steps/general.ts @@ -18,6 +18,8 @@ import { WP_BASE_URL } from '../../../config/wp.config'; import { createReference, compareReference } from "../../../utils/helpers"; import type { Section } from "../../../utils/types"; import { Page } from '@playwright/test'; +import { exists } from "../../../utils/commands"; +import { WP_SSH_ROOT_DIR } from "../../../config/wp.config"; /** * Executes the step to log in. @@ -230,11 +232,13 @@ Then('I should see {string}', async function (this: ICustomWorld, text) { * Executes the step to check for errors in debug.log. */ Then('I must not see any error in debug.log', async function (this: ICustomWorld){ - // Goto WP Rocket dashboard - await this.utils.gotoWpr(); - await this.page.waitForLoadState('load', { timeout: 30000 }); - // Assert that there is no related error in debug.log - await expect(this.page.locator('#wpr_debug_log_notice')).toBeHidden(); + // Define the path to debug.log + const debugLogPath = `${WP_SSH_ROOT_DIR}wp-content/debug.log`; + + // Check if debug.log exists + const debugLogExists = await exists(debugLogPath); + + await expect(debugLogExists).toBe(false); }); /** diff --git a/utils/commands.ts b/utils/commands.ts index e8efb41..b56daf5 100644 --- a/utils/commands.ts +++ b/utils/commands.ts @@ -155,19 +155,19 @@ export async function exists(filePath: string): Promise { let command: string; if(configurations.type === ServerType.docker) { - command = `docker exec -T ${configurations.docker.container} test -f ${filePath}`; + command = `docker exec -T ${configurations.docker.container} test -f ${filePath}; echo $?`; } else if(configurations.type === ServerType.external) { - command = `ssh -i ${configurations.ssh.key} ${configurations.ssh.username}@${configurations.ssh.address} "test -f ${filePath}"`; + command = `ssh -i ${configurations.ssh.key} ${configurations.ssh.username}@${configurations.ssh.address} 'test -f ${filePath}; echo $?'`; } else { - command = `test -f ${filePath}`; + command = `test -f ${filePath}; echo $?`; } try { - await exec(command, { + const result = await exec(command, { cwd: configurations.rootDir, async: false }); - return true; + return result.stdout.trim() === '0'; } catch (error) { return false; } @@ -224,6 +224,19 @@ export async function activatePlugin(name: string): Promise { await wp(`plugin activate ${name}`) } +/** + * Executes a SQL query on the WordPress database using WP-CLI. + * + * @function + * @name query + * @async + * @param {string} query - The SQL query to be executed. + * @returns {Promise} - A Promise that resolves when the query is executed. + */ +export async function query(query: string): Promise { + await wp(`db query "${query}"`) +} + /** * Deactivates a WordPress plugin using the WP-CLI command. *