Files

47 lines
3.3 KiB
JavaScript

// Optional browser smoke test. Install Playwright separately; the application
// itself has no Node dependency. Start a server with disposable data first.
import { createRequire } from "node:module";
import assert from "node:assert/strict";
const require = createRequire(import.meta.url);
const { chromium } = require(process.env.VERSTACK_PLAYWRIGHT || "playwright");
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
const errors = [];
const repository = `Browser smoke test ${Date.now()}`;
page.on("pageerror", (error) => errors.push(error.message));
try {
await page.goto(process.env.VERSTACK_TEST_URL || "http://127.0.0.1:18765");
await page.waitForFunction(() => document.getElementById("notice").textContent.includes("ready"));
await page.getByRole('link', {name:'Import',exact:true}).click();
await page.locator('[name="repository"]').fill(repository);
await page.locator('[name="version"]').fill("2");
await page.locator('[name="released_at"]').fill("2025-05-01");
await page.locator('[name="file"]').setInputFiles({ name: "config.txt", mimeType: "text/plain", buffer: Buffer.from("mode=enabled\nvolume=80\n") });
await page.getByRole("button", { name: "Import & verify" }).click();
await page.waitForFunction(() => document.getElementById("notice").textContent.includes("committed"));
await page.locator("#media-kind").selectOption("all");
await page.getByRole("button", { name: "Inspect", exact: true }).click();
await page.waitForFunction(() => document.getElementById("preview").textContent.includes("mode=enabled"));
assert.match(await page.locator("#preview").innerText(), /mode=enabled/);
assert.match(await page.locator("#snapshots").innerText(), /2025-05-01/);
const [download] = await Promise.all([page.waitForEvent("download"), page.getByRole("link", { name: "Download", exact: true }).click()]);
assert.equal(download.suggestedFilename(), "config.txt");
await page.locator(".tools summary").click();
await page.getByRole("button", { name: "Verify retained bytes" }).click();
await page.waitForFunction(() => document.getElementById("notice").textContent.includes("hashes verified"));
await page.getByRole("link", {name:"Import",exact:true}).click();
await page.locator('[name="version"]').fill("1");
await page.locator('[name="file"]').setInputFiles({ name: "config.txt", mimeType: "text/plain", buffer: Buffer.from("mode=disabled\nvolume=70\n") });
await page.getByRole("button", { name: "Import & verify" }).click();
await page.waitForFunction(() => document.getElementById("notice").textContent.includes("committed"));
await page.locator("#breadcrumbs").getByRole("button", {name:repository,exact:true}).click();
await page.getByRole("button", { name: "Compare", exact: true }).first().click();
await page.getByRole("button", { name: "Compare", exact: true }).first().click();
await page.waitForFunction(() => document.getElementById("diff").textContent.includes("changed"));
assert.equal(errors.length, 0, errors.join("\n"));
await page.screenshot({ path: process.env.VERSTACK_SCREENSHOT || "/tmp/verstack-ui.png", fullPage: true });
console.log("Browser smoke passed: upload, release date, browse, preview, download, verify, compare; no JavaScript errors.");
} finally {
await browser.close();
}