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.
176 lines
8.8 KiB
JavaScript
176 lines
8.8 KiB
JavaScript
// Run against pnpm dev with PLAYWRIGHT_MODULE and CHROME_PATH if needed.
|
|
import { createRequire } from "node:module";
|
|
import { mkdirSync, readFileSync } from "node:fs";
|
|
import assert from "node:assert/strict";
|
|
const require = createRequire(import.meta.url);
|
|
const { version } = JSON.parse(readFileSync(new URL("../../../package.json", import.meta.url), "utf8"));
|
|
mkdirSync(".audit", { recursive: true });
|
|
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 context = await browser.newContext({ viewport: { width: 1100, height: 800 } });
|
|
const page = await context.newPage();
|
|
const settingsPage = await context.newPage();
|
|
const errors = [];
|
|
page.on("pageerror", error => errors.push(error.message));
|
|
settingsPage.on("pageerror", error => errors.push(error.message));
|
|
await context.addInitScript(() => {
|
|
window.isTauri = true;
|
|
const disk = { "note.txt": "Original note" };
|
|
const writes = [];
|
|
window.__TEST__ = { disk, writes };
|
|
window.__TAURI_INTERNALS__ = {
|
|
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
|
transformCallback: () => 1, unregisterCallback: () => {},
|
|
invoke: async (command, args = {}) => {
|
|
if (command === "plugins_snapshot") return { root: "D:\\AppData\\RuneStone\\plugins", plugins: [] };
|
|
if (command === "workspace_last_path") return "D:\\Notes";
|
|
if (command === "workspace_open") return { root: "D:\\Notes", name: "Notes", watch_mode: "native" };
|
|
if (command === "workspace_list") return args.rel ? [] : [{ name: "note.txt", rel_path: "note.txt", kind: "file" }];
|
|
if (command === "workspace_read") { if (args.rel in disk) return disk[args.rel]; throw "Missing file"; }
|
|
if (command === "workspace_write") { disk[args.rel] = args.contents; writes.push(args); return; }
|
|
return null;
|
|
},
|
|
};
|
|
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
|
});
|
|
const url = process.env.SMOKE_URL || "http://127.0.0.1:1420";
|
|
const settings = settingsPage.getByRole("dialog", { name: "Settings", exact: true });
|
|
const trigger = page.getByRole("button", { name: "Settings (Ctrl+,)", exact: true });
|
|
async function showSettings(shortcut = false) {
|
|
if (shortcut) await page.keyboard.press("Control+,");
|
|
else await trigger.click();
|
|
await settingsPage.goto(`${url}/?settingsWindow=true`);
|
|
await settings.waitFor();
|
|
}
|
|
async function closeSettings() {
|
|
await settingsPage.goto("about:blank");
|
|
await page.bringToFront();
|
|
}
|
|
const interval = settings.getByRole("spinbutton", { name: "Auto-save interval" });
|
|
const enabled = settings.getByRole("switch", { name: "Auto-save", exact: true });
|
|
async function changeSeconds(value) {
|
|
await interval.fill(String(value));
|
|
await interval.press("Tab");
|
|
}
|
|
async function edit(value) {
|
|
await page.evaluate(async text => {
|
|
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
|
|
monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected).setValue(text);
|
|
}, value);
|
|
}
|
|
const writes = () => page.evaluate(() => window.__TEST__.writes.length);
|
|
try {
|
|
await page.clock.install();
|
|
await page.goto(url);
|
|
await page.locator(".ws").filter({ hasText: "Notes" }).waitFor();
|
|
await showSettings();
|
|
assert.equal(await interval.inputValue(), "5");
|
|
assert(await enabled.isChecked());
|
|
await changeSeconds(2);
|
|
await settings.getByRole("status").filter({ hasText: "Changes saved." }).waitFor();
|
|
await closeSettings();
|
|
await page.reload();
|
|
await showSettings();
|
|
assert.equal(await interval.inputValue(), "2", "Interval survives reload");
|
|
await changeSeconds(0);
|
|
await settings.getByRole("alert").filter({ hasText: "whole number" }).waitFor();
|
|
assert.equal(await page.evaluate(() => JSON.parse(localStorage.getItem("runestone.settings")).autosaveSeconds), 2);
|
|
await changeSeconds(2);
|
|
await settings.getByRole("textbox", { name: "Search settings" }).fill("plugins");
|
|
await settings.getByText("No plugins installed.", { exact: true }).waitFor();
|
|
assert(await settings.getByRole("button", { name: "Install plugin ZIP", exact: true }).isEnabled());
|
|
await settings.getByRole("textbox", { name: "Search settings" }).fill("no such setting");
|
|
await settings.getByText("No settings found", { exact: true }).waitFor();
|
|
await settings.getByRole("button", { name: "Clear search" }).click();
|
|
await settingsPage.screenshot({ path: ".audit/settings-general.png" });
|
|
await closeSettings();
|
|
|
|
await page.keyboard.press("Control+p");
|
|
await page.getByRole("textbox", { name: "Find a file" }).fill("note.txt");
|
|
await page.getByRole("dialog").getByRole("button").filter({ hasText: "note.txt" }).first().click();
|
|
await page.locator(".monaco-editor textarea").waitFor();
|
|
await page.clock.pauseAt(new Date(await page.evaluate(() => Date.now()) + 1000));
|
|
await showSettings();
|
|
await changeSeconds(3);
|
|
await closeSettings();
|
|
await edit("Saved at three seconds");
|
|
const before = await writes();
|
|
await page.clock.runFor(2100);
|
|
assert.equal(await writes(), before, "Old two-second timer is removed");
|
|
await page.clock.runFor(1000);
|
|
assert.equal(await writes(), before + 1, "New interval saves the dirty buffer");
|
|
await page.clock.runFor(3100);
|
|
assert.equal(await writes(), before + 1, "Clean files are not rewritten");
|
|
await showSettings();
|
|
await enabled.uncheck();
|
|
assert(await interval.isDisabled());
|
|
await closeSettings();
|
|
await edit("Manual save while auto-save is disabled");
|
|
await page.clock.runFor(10000);
|
|
assert.equal(await writes(), before + 1);
|
|
await page.keyboard.press("Control+s");
|
|
await page.waitForFunction(count => window.__TEST__.writes.length === count, before + 2);
|
|
await page.locator(".monaco-editor textarea").focus();
|
|
await showSettings(true);
|
|
await settings.waitFor();
|
|
await closeSettings();
|
|
await page.locator(".monaco-editor textarea").focus();
|
|
await page.keyboard.press("F1");
|
|
await page.getByRole("dialog", { name: "Help and about", exact: true }).waitFor();
|
|
await page.keyboard.press("Escape");
|
|
|
|
const other = await context.newPage();
|
|
await other.goto(`${url}/?settingsWindow=true`);
|
|
assert.equal(await other.getByRole("spinbutton", { name: "Auto-save interval" }).inputValue(), "3");
|
|
assert.equal(await other.getByRole("switch", { name: "Auto-save", exact: true }).isChecked(), false);
|
|
await other.getByRole("button", { name: "Restore defaults" }).click();
|
|
await page.waitForFunction(() => JSON.parse(localStorage.getItem("runestone.settings")).autosaveEnabled);
|
|
await showSettings();
|
|
await enabled.waitFor();
|
|
assert(await enabled.isChecked(), "Other windows receive changes");
|
|
assert.equal(await interval.inputValue(), "5");
|
|
await closeSettings();
|
|
await edit("Auto-save enabled from another window");
|
|
await page.clock.runFor(5100);
|
|
assert.equal(await writes(), before + 3);
|
|
await other.close();
|
|
|
|
await showSettings();
|
|
await settingsPage.evaluate(() => {
|
|
window.__SET_ITEM__ = Storage.prototype.setItem;
|
|
Storage.prototype.setItem = () => { throw new Error("Storage unavailable"); };
|
|
});
|
|
await changeSeconds(7);
|
|
await settings.getByRole("alert").filter({ hasText: "Could not save" }).waitFor();
|
|
await settingsPage.evaluate(() => { Storage.prototype.setItem = window.__SET_ITEM__; });
|
|
await closeSettings();
|
|
await showSettings();
|
|
assert.equal(await interval.inputValue(), "5", "Failed writes preserve applied settings");
|
|
await closeSettings();
|
|
|
|
await page.getByRole("button", { name: "Help and about (F1)" }).click();
|
|
const help = page.getByRole("dialog", { name: "Help and about", exact: true });
|
|
await help.getByRole("heading", { name: "RuneStone", exact: true }).waitFor();
|
|
await help.getByText(`Version ${version}`, { exact: false }).waitFor();
|
|
await page.screenshot({ path: ".audit/settings-help.png" });
|
|
await page.keyboard.press("Escape");
|
|
await page.keyboard.press("Control+b");
|
|
await showSettings(true);
|
|
await settings.waitFor();
|
|
await closeSettings();
|
|
await page.keyboard.press("F1");
|
|
await help.waitFor();
|
|
await page.keyboard.press("Escape");
|
|
await settingsPage.setViewportSize({ width: 540, height: 420 });
|
|
await showSettings(true);
|
|
await settings.waitFor();
|
|
assert(await settings.evaluate(el => el.scrollWidth === el.clientWidth), "Narrow layout fits");
|
|
await settingsPage.screenshot({ path: ".audit/settings-narrow.png" });
|
|
for (let i = 0; i < 12; i++) {
|
|
await settingsPage.keyboard.press("Tab");
|
|
assert(await settings.evaluate(el => el.contains(document.activeElement)), "Focus stays in the modal");
|
|
}
|
|
assert.deepEqual(errors, []);
|
|
console.log("Settings smoke passed: timer changes, disabled auto-save, manual saves, persistence, cross-window updates, validation, storage failure, help, search, focus, shortcuts, and narrow layout.");
|
|
} finally { await browser.close(); }
|