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
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 168 additions and 46 deletions

View file

@ -246,6 +246,36 @@ let needSetup = false;
log.debug("test", request.body);
response.send("OK");
});
const fs = require("fs");
app.get("/_e2e/take-sqlite-snapshot", async (request, response) => {
await Database.close();
try {
fs.cpSync(Database.sqlitePath, `${Database.sqlitePath}.e2e-snapshot`);
} catch (err) {
throw new Error("Unable to copy SQLite DB.");
}
await Database.connect();
response.send("Snapshot taken.");
});
app.get("/_e2e/restore-sqlite-snapshot", async (request, response) => {
if (!fs.existsSync(`${Database.sqlitePath}.e2e-snapshot`)) {
throw new Error("Snapshot doesn't exist.");
}
await Database.close();
try {
fs.cpSync(`${Database.sqlitePath}.e2e-snapshot`, Database.sqlitePath);
} catch (err) {
throw new Error("Unable to copy snapshot file.");
}
await Database.connect();
response.send("Snapshot restored.");
});
}
// Robots.txt