Move the tests from scripts/ to tests/ by feature
Unit tests go to tests/unit/<area>/, browser smoke tests to tests/smoke/<area>/, and tests against a running desktop app to tests/native/. Files named after dates, work passes, or Kanban cards get feature names, for example editorOctober12 -> editor/footnotes. scripts/ keeps the build, release, and package tools. Plugin repositories import scripts/packagePlugin.mjs, and the Terminal smoke test imports scripts/pluginMocks.mjs, which now re-exports the harness copy. The unit tests get their own type check (tests/tsconfig.json) with Node types. pnpm check runs it after the app check. Add @types/node and fix the three test mocks that it reported.
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
import { createRequire } from "node:module";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const origin = process.env.SMOKE_URL || "http://127.0.0.1:1420";
|
||||
const errors = [];
|
||||
await mkdir(".audit", { recursive: true });
|
||||
try {
|
||||
const context = await browser.newContext({ viewport: { width: 1152, height: 815 } });
|
||||
await context.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
let sequence = 0;
|
||||
const callbacks = new Map();
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: callback => { const id = ++sequence; callbacks.set(id, callback); return id; },
|
||||
unregisterCallback: id => callbacks.delete(id),
|
||||
invoke: async (command, args = {}) => {
|
||||
if (command === "plugins_snapshot") return { root: "D:/RuneStone/plugins", plugins: Array.from({ length: 7 }, (_, index) => ({
|
||||
manifest: { schemaVersion: 1, id: `org.example.plugin-${index}`, name: `Example plugin ${index + 1}`, author: "RuneStone Team", description: "A plugin description with enough text to check readable wrapping.", version: "0.1.1", apiVersion: 1, entry: "main.js", access: "full-app" },
|
||||
enabled: false, hash: "test", installedAt: 1791390000000, path: `D:/RuneStone/plugins/plugin-${index}`, error: null, removal: false,
|
||||
})) };
|
||||
if (command === "workspace_last_path") return null;
|
||||
if (command === "plugin:event|listen") return args.handler;
|
||||
if (command === "plugin:window|is_maximized") return false;
|
||||
return null;
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
const main = await context.newPage();
|
||||
const settings = await context.newPage();
|
||||
for (const page of [main, settings]) {
|
||||
page.setDefaultTimeout(7000);
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
}
|
||||
await main.goto(origin);
|
||||
await settings.goto(`${origin}/?settingsWindow=true`);
|
||||
await settings.getByRole("heading", { name: "General", exact: true }).waitFor();
|
||||
const header = settings.locator("dialog > header");
|
||||
const mainHeader = main.locator(".header");
|
||||
assert.equal((await header.boundingBox()).height, (await mainHeader.boundingBox()).height, "Settings and main title bars share their height");
|
||||
for (const name of ["Minimize window", "Maximize window", "Close window"]) {
|
||||
const a = await main.getByRole("button", { name, exact: true }).boundingBox();
|
||||
const b = await settings.getByRole("button", { name, exact: true }).boundingBox();
|
||||
assert.equal(a.width, b.width);
|
||||
assert.equal(a.height, b.height, `${name} has the same dimensions in both windows`);
|
||||
}
|
||||
await settings.getByRole("button", { name: "Plug-ins", exact: true }).click();
|
||||
await settings.getByRole("switch", { name: "Example plugin 1", exact: true }).waitFor();
|
||||
const content = settings.locator(".content");
|
||||
const pluginRows = content.locator(".row");
|
||||
assert.equal(await pluginRows.count(), 7);
|
||||
for (const theme of ["dark", "light"]) {
|
||||
await settings.evaluate(value => document.documentElement.dataset.theme = value, theme);
|
||||
for (const width of [1152, 540, 360]) {
|
||||
await settings.setViewportSize({ width, height: width === 1152 ? 815 : 420 });
|
||||
assert(await settings.evaluate(() => document.documentElement.scrollWidth <= innerWidth));
|
||||
assert(await content.evaluate(element => element.scrollWidth <= element.clientWidth), "The plugin content does not scroll horizontally");
|
||||
const rows = await pluginRows.evaluateAll(elements => elements.map(element => element.getBoundingClientRect().height));
|
||||
if (width === 1152) {
|
||||
assert(rows.every(height => height <= 100), `Desktop plugin rows stay compact: ${rows}`);
|
||||
const count = await pluginRows.evaluateAll(elements => {
|
||||
const container = elements[0].closest(".content").getBoundingClientRect();
|
||||
return elements.filter(element => element.getBoundingClientRect().bottom <= container.bottom).length;
|
||||
});
|
||||
assert(count >= 5, `At least five complete plugin rows fit at the screenshot size, got ${count}`);
|
||||
}
|
||||
const copy = pluginRows.first().locator(".plugin-copy");
|
||||
const controls = pluginRows.first().locator(".controls");
|
||||
const a = await copy.boundingBox(), b = await controls.boundingBox();
|
||||
assert(a.x + a.width <= b.x + 1 || a.y + a.height <= b.y + 1, "Plugin text does not overlap its actions");
|
||||
for (const button of await controls.getByRole("button").all()) {
|
||||
const bounds = await button.boundingBox();
|
||||
assert(bounds.width >= 28 && bounds.height >= 28);
|
||||
assert(await button.getAttribute("aria-label"));
|
||||
}
|
||||
await settings.screenshot({ path: `.audit/settings-density-${theme}-${width}.png` });
|
||||
}
|
||||
}
|
||||
await settings.setViewportSize({ width: 540, height: 420 });
|
||||
await settings.getByRole("button", { name: "Install from Git link", exact: true }).click();
|
||||
const install = settings.getByRole("dialog", { name: "Install from Git link", exact: true });
|
||||
await install.waitFor();
|
||||
assert(await install.getByRole("textbox", { name: "Repository link", exact: true }).isVisible());
|
||||
assert.equal(await settings.evaluate(() => document.activeElement?.textContent), "Cancel");
|
||||
await settings.keyboard.press("Escape");
|
||||
await install.waitFor({ state: "detached" });
|
||||
assert.equal(await settings.evaluate(() => document.activeElement?.textContent), "Install from Git link");
|
||||
await settings.getByRole("button", { name: "General", exact: true }).click();
|
||||
assert(await settings.getByRole("spinbutton", { name: "Auto-save interval", exact: true }).isVisible());
|
||||
await settings.evaluate(async () => {
|
||||
const { pluginTools } = await import("/src/lib/plugins/external.ts");
|
||||
pluginTools.set(Array.from({ length: 12 }, (_, index) => ({ owner: "org.example.plugin-0", id: `settings-${index}`, title: `Plugin settings ${index + 1}`, surface: "settings" })));
|
||||
});
|
||||
await settings.setViewportSize({ width: 360, height: 420 });
|
||||
const sidebar = settings.locator("dialog aside");
|
||||
assert((await sidebar.boundingBox()).height <= 154, "Many plugin categories leave space for setting controls");
|
||||
assert(await sidebar.evaluate(element => element.scrollWidth <= element.clientWidth));
|
||||
await settings.getByRole("button", { name: "Plugin settings 12", exact: true }).scrollIntoViewIfNeeded();
|
||||
const category = await settings.getByRole("button", { name: "Plugin settings 12", exact: true }).boundingBox();
|
||||
const navigation = await sidebar.boundingBox();
|
||||
assert(category.y >= navigation.y && category.y + category.height <= navigation.y + navigation.height, "Every plugin category remains reachable");
|
||||
assert(await settings.getByRole("spinbutton", { name: "Auto-save interval", exact: true }).isVisible());
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("Settings density smoke passed: matching title bars and window controls, seven plugin rows, compact layout, readable text, accessible actions, both themes, narrow layouts, Git dialog focus, and many plugin categories.");
|
||||
} finally { await browser.close(); }
|
||||
Reference in New Issue
Block a user