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.
96 lines
4.8 KiB
JavaScript
96 lines
4.8 KiB
JavaScript
// Run against pnpm dev with PLAYWRIGHT_MODULE and CHROME_PATH if needed.
|
|
import { createRequire } from "node:module";
|
|
import assert from "node:assert/strict";
|
|
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 context = await browser.newContext({ viewport: { width: 1280, height: 800 } });
|
|
await context.addInitScript(() => {
|
|
window.isTauri = true;
|
|
window.__TAURI_INTERNALS__ = {
|
|
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
|
transformCallback: () => 1, unregisterCallback: () => {},
|
|
invoke: async (command, args = {}) => {
|
|
if (command === "plugins_snapshot") return { root: "D:\\LayoutTest\\plugins", plugins: [] };
|
|
if (command === "workspace_last_path") return "D:\\LayoutTest";
|
|
if (command === "workspace_open") return { root: "D:\\LayoutTest", name: "LayoutTest", watch_mode: "native" };
|
|
if (command === "workspace_list") return args.rel ? [] : [{ name: "note.md", rel_path: "note.md", kind: "file" }];
|
|
if (command === "workspace_read") {
|
|
if (args.rel === "note.md") return "# Layout test\n\nA note.\n";
|
|
throw new Error("Missing file");
|
|
}
|
|
return null;
|
|
},
|
|
};
|
|
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
|
});
|
|
const errors = [];
|
|
context.on("page", page => page.on("pageerror", error => errors.push(error.message)));
|
|
const url = process.env.SMOKE_URL || "http://127.0.0.1:1420";
|
|
let page = await context.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
async function ready() { await page.getByRole("button", { name: /^(Hide|Show) outline$/ }).waitFor(); }
|
|
async function reopen() {
|
|
await page.close();
|
|
page = await context.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
await page.goto(url);
|
|
await ready();
|
|
}
|
|
async function resize(index, x) {
|
|
const box = await page.locator(".gutter-v").nth(index).boundingBox();
|
|
await page.mouse.move(box.x + box.width / 2, box.y + 60);
|
|
await page.mouse.down();
|
|
await page.mouse.move(x, box.y + 60);
|
|
await page.mouse.up();
|
|
}
|
|
async function widths() {
|
|
return page.locator(".shell").evaluate(element => [element.style.getPropertyValue("--left"), element.style.getPropertyValue("--right")]);
|
|
}
|
|
try {
|
|
await page.goto(url);
|
|
await ready();
|
|
await page.getByText("LayoutTest", { exact: true }).waitFor();
|
|
await page.keyboard.press("Control+p");
|
|
await page.getByRole("textbox", { name: "Find a file" }).fill("note.md");
|
|
await page.getByRole("dialog").getByRole("button").filter({ hasText: "note.md" }).click();
|
|
await page.locator(".cm-content").waitFor();
|
|
await page.getByRole("button", { name: "Hide outline", exact: true }).click();
|
|
await page.keyboard.press("Control+e");
|
|
await page.locator(".monaco-editor").waitFor();
|
|
assert.equal(await page.locator(".right").count(), 0);
|
|
await page.keyboard.press("Control+e");
|
|
await page.locator(".cm-content").waitFor();
|
|
assert.equal(await page.locator(".right").count(), 0);
|
|
console.log("PASS: hidden outline stays hidden across Writer and IDE changes");
|
|
await page.reload();
|
|
await page.getByRole("button", { name: "Show outline", exact: true }).waitFor();
|
|
assert.equal(await page.locator(".right").count(), 0);
|
|
await reopen();
|
|
await page.getByRole("button", { name: "Show outline", exact: true }).waitFor();
|
|
console.log("PASS: hidden outline survives reload and window reopen");
|
|
|
|
await page.getByRole("button", { name: "Show outline", exact: true }).click();
|
|
await resize(0, 330);
|
|
await resize(1, 970);
|
|
const resized = await widths();
|
|
assert.deepEqual(resized, ["330px", "310px"]);
|
|
await page.getByRole("button", { name: "Bookmarks", exact: true }).click();
|
|
await reopen();
|
|
assert.deepEqual(await widths(), resized);
|
|
assert.equal(await page.getByRole("button", { name: "Bookmarks", exact: true }).getAttribute("aria-pressed"), "true");
|
|
await page.getByRole("button", { name: "Hide outline", exact: true }).waitFor();
|
|
console.log("PASS: resized sidebars and chosen navigation view survive reopen");
|
|
|
|
await page.getByRole("button", { name: "Bookmarks", exact: true }).click();
|
|
await page.getByRole("button", { name: "Hide outline", exact: true }).click();
|
|
await reopen();
|
|
assert.equal(await page.locator(".left, .right").count(), 0);
|
|
await page.keyboard.press("Control+b");
|
|
assert.equal(await page.getByRole("button", { name: "Bookmarks", exact: true }).getAttribute("aria-pressed"), "true");
|
|
await page.getByRole("button", { name: "Show outline", exact: true }).click();
|
|
assert.deepEqual(await widths(), resized);
|
|
console.log("PASS: collapsed sidebars retain their sizes and navigation view");
|
|
assert.deepEqual(errors, []);
|
|
} finally { await browser.close(); }
|