Improve Playwright/E2E testing setup (#5056)

Co-authored-by: Frank Elsinga <frank@elsinga.de>
This commit is contained in:
Shaun
2024-08-28 17:18:04 -04:00
committed by GitHub
parent 01210ce88d
commit 3d9bbe1a62
6 changed files with 168 additions and 46 deletions

View File

@@ -1,3 +1,9 @@
const fs = require("fs");
const path = require("path");
const serverUrl = require("../../config/playwright.config.js").url;
const dbPath = "./../../data/playwright-test/kuma.db";
/**
* @param {TestInfo} testInfo Test info
* @param {Page} page Page
@@ -25,3 +31,32 @@ export async function login(page) {
await page.getByRole("button", { name: "Log in" }).click();
await page.isVisible("text=Add New Monitor");
}
/**
* Determines if the SQLite database has been created. This indicates setup has completed.
* @returns {boolean} True if exists
*/
export function getSqliteDatabaseExists() {
return fs.existsSync(path.resolve(__dirname, dbPath));
}
/**
* Makes a request to the server to take a snapshot of the SQLite database.
* @param {Page|null} page Page
* @returns {Promise<Response>} Promise of response from snapshot request.
*/
export async function takeSqliteSnapshot(page = null) {
if (page) {
return page.goto("./_e2e/take-sqlite-snapshot");
} else {
return fetch(`${serverUrl}/_e2e/take-sqlite-snapshot`);
}
}
/**
* Makes a request to the server to restore the snapshot of the SQLite database.
* @returns {Promise<Response>} Promise of response from restoration request.
*/
export async function restoreSqliteSnapshot() {
return fetch(`${serverUrl}/_e2e/restore-sqlite-snapshot`);
}