Move the smoke tests onto the shared harness
Each smoke test now uses tests/smoke/_harness/ for Playwright, the Tauri IPC mock, the in-memory workspace, and output folders, instead of its own copy. The tests keep their interactions and assertions. Mock handlers that the app never calls are gone. - Split the four mixed regression scripts into 18 feature tests. - Update tests that broke when the app changed on purpose. Each update cites the app source that shows the new behavior. - Mark two real app defects with @known-issue: the settings window controls are 1px shorter than the main window controls, and plugin tabs cannot be reordered by dragging without a workspace. - Merge three palette unit tests into one table-driven test. - The native tests load Playwright through the harness and read NATIVE_CDP_URL, with their old variable names as fallbacks. - A failed smoke test saves a screenshot and prints the console errors. - The runner runs failed tests once more, alone, and reports a test that then passes as flaky. Result: 89 passed, 1 flaky, 2 known issues, 0 failed. Before, 45 of 78 passed.
This commit is contained in:
@@ -1,85 +1,71 @@
|
||||
import { createRequire } from "node:module";
|
||||
// New files keep exact names and extensions, renames change the code language, and Writer menus work in both themes.
|
||||
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 page = await browser.newPage({ viewport: { width: 1280, height: 900 } });
|
||||
page.setDefaultTimeout(15000);
|
||||
const errors = [];
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
await page.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const root = "C:\\editor-files-smoke";
|
||||
const files = new Map([
|
||||
["note.md", "Mispelled text.\n\n| Word | Value |\n| --- | --- |\n| Speling | Other |\n"],
|
||||
["hello.txt", "print('hello')\n"],
|
||||
["notes/existing.md", "Existing note"],
|
||||
]);
|
||||
window.editorFilesTest = { files, calls: [] };
|
||||
let sequence = 0;
|
||||
window.__TAURI_INTERNALS__ = {
|
||||
metadata: { currentWindow: { label: "main" }, currentWebview: { label: "main" } },
|
||||
transformCallback: () => ++sequence, unregisterCallback: () => {},
|
||||
invoke: async (command, args = {}) => {
|
||||
window.editorFilesTest.calls.push({ command, args });
|
||||
if (command === "plugin:event|listen") return ++sequence;
|
||||
if (command === "plugin:event|unlisten") return;
|
||||
if (command === "workspace_last_path") return root;
|
||||
if (command === "workspace_open") return { root, name: "editor-files-smoke", watch_mode: "native" };
|
||||
if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("missing"); return files.get(args.rel); }
|
||||
if (command === "workspace_write") { files.set(args.rel, args.contents); return; }
|
||||
if (command === "workspace_list") {
|
||||
const prefix = args.rel ? args.rel + "/" : "", entries = new Map();
|
||||
for (const path of files.keys()) {
|
||||
if (!path.startsWith(prefix) || path.startsWith(".runestone/")) continue;
|
||||
const tail = path.slice(prefix.length), name = tail.split("/")[0];
|
||||
entries.set(name, { name, rel_path: prefix + name, kind: tail.includes("/") ? "folder" : "file" });
|
||||
}
|
||||
return [...entries.values()];
|
||||
}
|
||||
if (command === "workspace_create") {
|
||||
if (files.has(args.rel)) throw new Error("path already exists");
|
||||
files.set(args.rel, ""); return;
|
||||
}
|
||||
if (command === "workspace_rename") {
|
||||
if (files.has(args.to)) throw new Error("destination already exists");
|
||||
files.set(args.to, files.get(args.from)); files.delete(args.from); return;
|
||||
}
|
||||
if (command === "workspace_search") return [];
|
||||
throw new Error(`Unhandled IPC: ${command}`);
|
||||
import { mockTauri, runSmoke, smokeUrl } from "../_harness/index.mjs";
|
||||
|
||||
await runSmoke("tree/newFiles", async ({ page }) => {
|
||||
await mockTauri(page, {
|
||||
commands: test => {
|
||||
const ws = test.workspace({
|
||||
root: "C:\\editor-files-smoke",
|
||||
files: {
|
||||
"note.md": "Mispelled text.\n\n| Word | Value |\n| --- | --- |\n| Speling | Other |\n",
|
||||
"hello.txt": "print('hello')\n",
|
||||
"notes/existing.md": "Existing note",
|
||||
},
|
||||
});
|
||||
const files = ws.files;
|
||||
test.files = files;
|
||||
return {
|
||||
...ws,
|
||||
workspace_list: args => ws.workspace_list(args).filter(entry => !entry.rel_path.startsWith(".runestone")),
|
||||
workspace_create: ({ rel }) => {
|
||||
if (files.has(rel)) throw new Error("path already exists");
|
||||
files.set(rel, "");
|
||||
},
|
||||
workspace_rename: ({ from, to }) => {
|
||||
if (files.has(to)) throw new Error("destination already exists");
|
||||
files.set(to, files.get(from));
|
||||
files.delete(from);
|
||||
},
|
||||
spelling_suggestions: ({ word }) => ({ language: "en-US", words: word === "Mispelled" ? ["Misspelled"] : [], misspelled: word === "Mispelled" }),
|
||||
};
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
const row = name => page.locator(`[data-tree-rel="${name}"]`);
|
||||
async function enterName(name) {
|
||||
await page.locator("#text-request").fill(name);
|
||||
await page.getByRole("button", { name: "Continue", exact: true }).click();
|
||||
}
|
||||
async function modelDetails() {
|
||||
return page.evaluate(async () => {
|
||||
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
|
||||
const editor = monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected);
|
||||
return editor && { language: editor.getModel().getLanguageId(), value: editor.getValue(), fontSize: editor.getOption(monaco.editor.EditorOption.fontSize) };
|
||||
});
|
||||
}
|
||||
try {
|
||||
await page.goto(process.env.SMOKE_URL || "http://127.0.0.1:1420");
|
||||
const row = name => page.locator(`[data-tree-rel="${name}"]`);
|
||||
// The file pane header offers New note and New folder (src/lib/layout/FileTree.svelte:886-887);
|
||||
// New file… is in the pane menu (src/lib/layout/FileTree.svelte:716-720).
|
||||
async function newRootFile() {
|
||||
await page.getByRole("navigation", { name: "Workspace files" }).click({ button: "right", position: { x: 80, y: 320 } });
|
||||
await page.getByRole("menuitem", { name: "New file…", exact: true }).click();
|
||||
}
|
||||
async function enterName(name) {
|
||||
await page.locator("#text-request").fill(name);
|
||||
await page.getByRole("button", { name: "Continue", exact: true }).click();
|
||||
}
|
||||
async function modelDetails() {
|
||||
return page.evaluate(async () => {
|
||||
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
|
||||
const editor = monaco.editor.getEditors().find(editor => editor.getDomNode()?.isConnected);
|
||||
return editor && { language: editor.getModel().getLanguageId(), value: editor.getValue(), fontSize: editor.getOption(monaco.editor.EditorOption.fontSize) };
|
||||
});
|
||||
}
|
||||
|
||||
await page.goto(smokeUrl);
|
||||
await row("note.md").waitFor();
|
||||
await page.getByRole("button", { name: "New file", exact: true }).click();
|
||||
await newRootFile();
|
||||
await enterName("LICENSE");
|
||||
await row("LICENSE").waitFor();
|
||||
await page.evaluate(() => window.editorFilesTest.files.set("LICENSE", "Keep this content"));
|
||||
await page.getByRole("button", { name: "New file", exact: true }).click();
|
||||
await page.evaluate(() => window.__TEST__.files.set("LICENSE", "Keep this content"));
|
||||
await newRootFile();
|
||||
await enterName("LICENSE");
|
||||
await page.getByText("path already exists", { exact: true }).waitFor();
|
||||
assert.equal(await page.evaluate(() => window.editorFilesTest.files.get("LICENSE")), "Keep this content");
|
||||
assert.equal(await page.evaluate(() => window.editorFilesTest.files.has("LICENSE 2")), false);
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.get("LICENSE")), "Keep this content");
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.has("LICENSE 2")), false);
|
||||
await row("notes").click({ button: "right" });
|
||||
await page.getByRole("menuitem", { name: "New file…", exact: true }).click();
|
||||
await enterName("hello_world.py");
|
||||
await row("notes/hello_world.py").waitFor();
|
||||
assert.equal(await page.evaluate(() => window.editorFilesTest.files.has("notes/hello_world.py.md")), false);
|
||||
assert.equal(await page.evaluate(() => window.__TEST__.files.has("notes/hello_world.py.md")), false);
|
||||
await row("hello.txt").dblclick();
|
||||
await page.waitForFunction(() => !!document.querySelector(".monaco-editor .view-line"));
|
||||
await row("hello.txt").click({ button: "right" });
|
||||
@@ -105,8 +91,8 @@ try {
|
||||
});
|
||||
for (const theme of ["dark", "light"]) {
|
||||
await page.evaluate(async mode => {
|
||||
const { saveAppearance } = await import('/src/lib/theme/appearance.ts');
|
||||
saveAppearance({ theme: 'default', mode });
|
||||
const { saveAppearance } = await import("/src/lib/theme/appearance.ts");
|
||||
saveAppearance({ theme: "default", mode });
|
||||
}, theme);
|
||||
const nativeAllowed = await page.evaluate(() => {
|
||||
window.writerTest.dispatch({ selection: { anchor: 3 } });
|
||||
@@ -115,7 +101,12 @@ try {
|
||||
line.dispatchEvent(event);
|
||||
return !event.defaultPrevented;
|
||||
});
|
||||
assert.equal(nativeAllowed, true, "The native spelling menu is available on plain text");
|
||||
// Writer combines spelling suggestions with the Markdown actions (docs/design-decisions.md UI-027;
|
||||
// src/lib/editor/LiveWriter.svelte:255-262 prevents the native menu and passes the spelling offset).
|
||||
assert.equal(nativeAllowed, false, "Plain text opens the shared Markdown menu instead of the native one");
|
||||
const textMenu = page.getByRole("menu", { name: "Markdown text actions", exact: true });
|
||||
await textMenu.getByRole("menuitem", { name: "Misspelled", exact: true }).waitFor();
|
||||
await page.keyboard.press("Escape");
|
||||
assert.equal(await page.getByRole("menu").count(), 0);
|
||||
await page.evaluate(() => { window.writerTest.focus(); });
|
||||
await page.keyboard.press("Shift+F10");
|
||||
@@ -137,6 +128,4 @@ try {
|
||||
}), true, "Active table text permits the native spelling menu");
|
||||
await page.locator(".cm-line").first().click();
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
console.log("PASS: exact filenames, extensionless creation, extension rename and language, equal code font sizes, native spelling event, shared selection and table menus in both themes");
|
||||
} finally { await browser.close(); }
|
||||
}, { viewport: { width: 1280, height: 900 }, timeout: 15000 });
|
||||
|
||||
Reference in New Issue
Block a user