Skip to content

Commit

Permalink
Replace check if debug.log exists by ssh
Browse files Browse the repository at this point in the history
  • Loading branch information
Miraeld committed Mar 29, 2024
1 parent 9add1ab commit 8741f7d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
14 changes: 9 additions & 5 deletions src/support/steps/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
});

/**
Expand Down
23 changes: 18 additions & 5 deletions utils/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,19 @@ export async function exists(filePath: string): Promise<boolean> {
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;
}
Expand Down Expand Up @@ -224,6 +224,19 @@ export async function activatePlugin(name: string): Promise<void> {
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<void>} - A Promise that resolves when the query is executed.
*/
export async function query(query: string): Promise<void> {
await wp(`db query "${query}"`)
}

/**
* Deactivates a WordPress plugin using the WP-CLI command.
*
Expand Down

0 comments on commit 8741f7d

Please sign in to comment.