From 37204c7c99cf915a389588517d26008141e1b015 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Tue, 7 Jan 2025 15:04:49 +0100 Subject: [PATCH 1/4] Added new command to read file from server --- utils/commands.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/utils/commands.ts b/utils/commands.ts index f19f0d0..7cfb2ba 100644 --- a/utils/commands.ts +++ b/utils/commands.ts @@ -499,4 +499,25 @@ export async function updatePostStatus(id: number, status: string): Promise} - A Promise that resolves after file content is read. + */ +export async function readFile(path: string): Promise { + const cwd = configurations.rootDir; + const command = wrapPrefix(`sudo cat ${path}`); + const result = exec(command, { cwd: cwd, async: false }); + + if (result.code !== 0) { + return ''; + } + + return result.stdout; +} + export default wp; \ No newline at end of file From b49916175bd3cf5fb695bcfc1742be98b2d2f54b Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Tue, 7 Jan 2025 15:05:26 +0100 Subject: [PATCH 2/4] Added new function to check wpr related error in debug.log --- utils/helpers.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/utils/helpers.ts b/utils/helpers.ts index bdb4c4b..b3b9a54 100644 --- a/utils/helpers.ts +++ b/utils/helpers.ts @@ -516,3 +516,26 @@ export const getScenarioTag = async(tags: Array): Promise => { return tag; } + +/** + * Check for WP Rocket related error in debug.log. + * + * @param {string} contents File content to be checked. + * + * @return {Promise} Promise that resolves after check is completed. + */ +export const isWprRelatedError = async(contents: string): Promise => { + const patterns: Array = [ + '/plugins/wp-rocket/', + 'wpr_rucss_used_css', + 'wpr_rocket_cache' + ]; + + for (const pattern of patterns) { + if (contents.includes(pattern)) { + return true; + } + } + + return false; +} From 87fa01dd386d6f6e2d8dcb1dec8d75821d9e5817 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Tue, 7 Jan 2025 15:06:06 +0100 Subject: [PATCH 3/4] Use new functions to check for wpr related error in debug.log before renaming log file --- src/support/hooks.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/support/hooks.ts b/src/support/hooks.ts index 0754b25..ed14a55 100644 --- a/src/support/hooks.ts +++ b/src/support/hooks.ts @@ -19,10 +19,10 @@ import { ChromiumBrowser, chromium } from '@playwright/test'; import { Sections } from '../common/sections'; import { selectors as pluginSelectors } from "./../common/selectors"; import { PageUtils } from "../../utils/page-utils"; -import { deleteFolder } from "../../utils/helpers"; +import { deleteFolder, isWprRelatedError } from "../../utils/helpers"; import {WP_SSH_ROOT_DIR,} from "../../config/wp.config"; import { After, AfterAll, Before, BeforeAll, Status, setDefaultTimeout } from "@cucumber/cucumber"; -import {rename, exists, rm, testSshConnection, installRemotePlugin, activatePlugin, uninstallPlugin} from "../../utils/commands"; +import {rename, exists, rm, testSshConnection, installRemotePlugin, activatePlugin, uninstallPlugin, readFile} from "../../utils/commands"; // import {configurations, getWPDir} from "../../utils/configurations"; /** @@ -167,8 +167,10 @@ After(async function (this: ICustomWorld, { pickle, result }) { const debugLogPath = `${WP_SSH_ROOT_DIR}wp-content/debug.log`; const debugLogExists = await exists(debugLogPath); + const debugLogContents = await readFile(debugLogPath); + const wprRelatedError = await isWprRelatedError(debugLogContents); - if (debugLogExists && previousScenarioName) { + if (debugLogExists && previousScenarioName && wprRelatedError) { // Close up white spaces. previousScenarioName = previousScenarioName.toLowerCase(); previousScenarioName = previousScenarioName.replaceAll(' ', '-'); From e5b7d01980514a9ee158100f2efdd73569b9419e Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Wed, 8 Jan 2025 13:03:13 +0100 Subject: [PATCH 4/4] Update patterns --- utils/helpers.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/helpers.ts b/utils/helpers.ts index b3b9a54..725a4b8 100644 --- a/utils/helpers.ts +++ b/utils/helpers.ts @@ -527,8 +527,7 @@ export const getScenarioTag = async(tags: Array): Promise => { export const isWprRelatedError = async(contents: string): Promise => { const patterns: Array = [ '/plugins/wp-rocket/', - 'wpr_rucss_used_css', - 'wpr_rocket_cache' + 'WP_Rocket' ]; for (const pattern of patterns) {