mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-21 01:47:29 +08:00
Improve Playwright/E2E testing setup (#5056)
Co-authored-by: Frank Elsinga <frank@elsinga.de>
This commit is contained in:
@@ -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`);
|
||||
}
|
||||
|
Reference in New Issue
Block a user