Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement/healthcheck command#110 #112

Merged
merged 14 commits into from
Jun 21, 2024
Merged
64 changes: 64 additions & 0 deletions healthcheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import chalk from "chalk";
import wp from "./utils/commands";
import {PageUtils} from './utils/page-utils';
import {WP_BASE_URL} from "./config/wp.config";
import {chromium as chrome, expect, Page} from '@playwright/test';
import {Sections} from "./src/common/sections";
import {selectors as pluginSelectors} from "./src/common/selectors";

export async function checkWPStatus(): Promise<void> {
const status: boolean = await wp('--info');

console.log(chalk.blue.bold('WP CLI Basic Setup Status'));
console.log(chalk.blue('=====================\n'));

let statusColor = chalk.green,
statusSymbol = '✔️',
message = 'WP CLI is running';

if(!status) {
statusColor = chalk.red;
statusSymbol = '❌';
message = 'WP CLI is not running, please check your config'
}

console.log(`'WP CLI health check': ${statusColor.bold(message.toUpperCase())} ${statusSymbol}`);
console.log(statusColor(message));
console.log(chalk.blue('-------------------------'));
}


async function setupBrowser(headless: boolean = false):Promise<Page> {
const browser = await chrome.launch({ headless });
const context = await browser.newContext();

return await context.newPage();
}

export async function openE2EPage(): Promise<void> {
const page = await setupBrowser(false);

await page.goto(WP_BASE_URL);
}

export async function auth(): Promise<void> {
const page = await setupBrowser(false);
const sections = new Sections(page, pluginSelectors);
const utils = new PageUtils(page, sections);

await utils.auth()
page.on('response', async (response) => {
expect(response.status()).not.toEqual(500);
expect(response.status()).not.toEqual(404);
});

await utils.wpAdminLogout()
}

(async (): Promise<void> => {
await checkWPStatus();
await openE2EPage();
await auth();

process.exit(0);
})();
Loading
Loading