// Run against `pnpm dev`. PLAYWRIGHT_MODULE may point to a shared installation. 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 page = await browser.newPage({ viewport: { width: 1440, height: 1000 } }); page.setDefaultTimeout(10000); const errors = []; await mkdir(".audit", { recursive: true }); page.on("console", message => { if (message.type() === "error" || message.type() === "warning") console.log(message.type(), message.text()); }); page.on("pageerror", error => errors.push(error.message)); await page.addInitScript(() => { window.isTauri = true; const root = "C:\\smoke-workspace"; const files = new Map([ ["notes/welcome.md", "---\ntitle: Welcome\n---\n\n# Working notes\n\nFirst paragraph.\n\n- [ ] A task\n\n[[second]]\n"], ["notes/second.md", "# Second note\n"], ["src/hello.py", "print('hello')\n"], ]); const callbacks = new Map(); const listeners = new Map(); let sequence = 0; const calls = []; const emit = (event, payload) => { for (const id of listeners.get(event) || []) callbacks.get(id)?.({ event, id, payload }); }; 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 = {}) => { calls.push({ command, args }); if (command === "plugin:event|listen") { const list = listeners.get(args.event) || []; list.push(args.handler); listeners.set(args.event, list); return args.handler; } if (command === "plugin:event|unlisten") { callbacks.delete(args.eventId); return; } if (command === "workspace_last_path") return root; if (command === "workspace_open") return { root, name: "smoke-workspace", 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") { if (args.expected !== undefined && files.get(args.rel) !== args.expected) throw new Error("Save blocked: file changed on disk"); files.set(args.rel, args.contents); emit("workspace-event", { root, kind: "modify", paths: [args.rel] }); return; } if (command === "workspace_list") { const prefix = args.rel ? args.rel + "/" : ""; const entries = new Map(); for (const path of files.keys()) { if (!path.startsWith(prefix) || (!prefix && path.startsWith(".runestone/"))) continue; const tail = path.slice(prefix.length); const 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("exists"); files.set(args.rel, ""); return; } if (command === "workspace_search") return []; if (command === "spelling_menu_install") return; if (command === "pty_open") { const data = [...new TextEncoder().encode("READY 🪨\r\n\x1b[6n")]; emit("pty-data", { id: args.id, data: data.slice(0, 8) }); emit("pty-data", { id: args.id, data: data.slice(8) }); await new Promise(resolve => setTimeout(resolve, 50)); return; } if (command.startsWith("pty_")) return; if (command === "plugin:dialog|message") return "Cancel"; throw new Error(`Unhandled IPC: ${command}`); }, }; window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: (_event, id) => callbacks.delete(id) }; window.__TEST__ = { files, calls, emit, root }; }); try { await mkdir('output/editor-template-hyphen', { recursive: true }); await page.goto(process.env.SMOKE_URL || 'http://127.0.0.1:1420'); await page.getByText('smoke-workspace', { exact: true }).waitFor(); // Save the empty task lines from the reported template, then create through // the normal note action so the filename receives the initial focus. await page.evaluate(async () => { const { saveNoteTemplate } = await import('/src/lib/workspace/templates.ts'); await saveNoteTemplate('To Do', '- [ ] \n'.repeat(10)); }); await page.getByRole('button', { name: 'New tab (Ctrl T)', exact: true }).click(); await page.getByRole('button', { name: 'New note', exact: true }).last().click(); await page.getByRole('menuitem', { name: 'To Do', exact: true }).click(); const title = page.getByRole('textbox', { name: 'Note filename', exact: true }); await title.waitFor(); await page.waitForFunction(() => document.activeElement?.getAttribute('aria-label') === 'Note filename'); await page.evaluate(async () => { const { EditorView } = await import('/node_modules/@codemirror/view/dist/index.js'); window.__CM__ = EditorView.findFromDOM(document.querySelector('.cm-content')); }); const count = () => page.locator('.writer-checkbox').count(); const expectCount = async expected => { await page.waitForFunction(expected => document.querySelectorAll('.writer-checkbox').length === expected, expected); assert.equal(await count(), expected); }; const setSource = source => page.evaluate(source => { window.__CM__.dispatch({ changes: { from: 0, to: window.__CM__.state.doc.length, insert: source }, selection: { anchor: source.length } }); window.__CM__.focus(); }, source); const plain = 'Some generic mobs or factions,\n-'; for (const mode of ['dark', 'light']) { await page.evaluate(async mode => (await import('/src/lib/theme/appearance.ts')).saveAppearance({ theme: 'default', mode }), mode); for (const width of [1440, 600]) { await page.setViewportSize({ width, height: width === 600 ? 760 : 1000 }); if (width === 600) { await page.getByRole('button', { name: 'Files', exact: true }).click(); await page.getByRole('button', { name: 'Hide outline', exact: true }).click(); } if (!(await title.isVisible())) await page.getByRole('button', { name: 'Rename note', exact: true }).click(); await title.focus(); await expectCount(10); await page.screenshot({ path: `output/editor-template-hyphen/${mode}-${width}-template-title.png` }); await page.keyboard.press('Escape'); await page.evaluate(() => { const view = window.__CM__; view.dispatch({ selection: { anchor: 0 } }); view.focus(); }); await expectCount(9); await page.keyboard.press('End'); await page.keyboard.type('First task'); await expectCount(10); await page.locator('.writer-checkbox').first().click(); assert.match(await page.evaluate(() => window.__CM__.state.sliceDoc()), /^- \[x\] First task/); await page.screenshot({ path: `output/editor-template-hyphen/${mode}-${width}-template-edit.png` }); await setSource(plain); assert.equal(await page.locator('.writer-h2').count(), 0, 'A lone hyphen must not enlarge preceding prose'); await page.screenshot({ path: `output/editor-template-hyphen/${mode}-${width}-single-hyphen.png` }); await page.keyboard.type(' Item'); assert.equal(await page.locator('.writer-h2').count(), 0, 'The hyphen continues into a list'); assert.equal(await page.evaluate(() => window.__CM__.state.sliceDoc()), plain + ' Item'); await setSource(plain + '-'); assert.equal(await page.locator('.writer-h2').count(), 1, 'Two hyphens retain Setext heading support'); await setSource('A normal heading\n===\n'); assert.equal(await page.locator('.writer-h1').count(), 1); // Restore the template for the next theme and size without an active body caret. await setSource('- [ ] \n'.repeat(10)); await page.getByRole('button', { name: 'Rename note', exact: true }).click(); if (width === 600) { await page.setViewportSize({ width: 1440, height: 1000 }); await page.getByRole('button', { name: 'Files', exact: true }).click(); await page.getByRole('button', { name: 'Show outline', exact: true }).click(); } } } assert.deepEqual(errors, []); console.log('PASS: template creation, filename focus, keyboard task entry, checkbox toggle, lone hyphen, list continuation, and Setext headings in both themes and narrow layouts.'); } catch (error) { await page.screenshot({ path: 'output/editor-template-hyphen/failure.png' }); throw error; } finally { await browser.close(); }