// The scenario table: the selectors, names, and feature switches of both modes, and the in-use action of each feature. // A value with `plugin` and `native` keys differs between the modes. Change the table when a stage changes a name. const PLUGIN_RELEASES = "D:/Users/KnottyWyvern/Documents"; export const TABLE = { /** The start time ends when this tree row is visible. */ knownRow: '[data-tree-rel="sample.pdf"]', /** The command palette. */ palette: { shortcut: "Control+Shift+P", input: "Find a command" }, /** The layout that the cleanup writes, so each start shows the file tree. */ layout: { leftOpen: true, rightOpen: true, leftWidth: 260, rightWidth: 240, leftView: "files" }, /** The settings section of the native feature switches. */ featuresSection: "features", features: { git: { plugin: { id: "runestone.git", repo: "runestone-git", tag: "v0.1.10", zip: `${PLUGIN_RELEASES}/RuneStone_Git/releases/runestone.git-0.1.10.zip` }, nativeKey: "git", navigation: "Source control", changeRow: { plugin: ".rs-git-row", native: ".source-control .row" }, changeCount: 50, changeFile: { plugin: ".rs-git-file", native: ".source-control .file" }, diffTab: "Git diff", diffText: "Changed after the last commit", graphCommand: "Show Git graph", /** Where the command is: `palette`, or `menu:`. Master lists plugin view commands only in the Plug-in views menu. */ graphCommandIn: { plugin: "menu:Plug-in views", native: "palette" }, graphTab: "Git graph", graphText: "Change fixture files, step 29", }, background: { plugin: { id: "runestone.bg-slideshow", repo: "runestone-bg-slideshow", tag: "v0.0.11", zip: `${PLUGIN_RELEASES}/RuneStone_Background_Slideshow/releases/runestone.bg-slideshow-0.0.11.zip` }, nativeKey: "background", /** * The style property of the body that holds the current background image. The action counts its changes. * Native: `backgroundHub.applyApp` (src/lib/plugins/backgrounds.ts) sets it for each new image of Background. */ imageProperty: { plugin: "--rs-background-image", native: "--rs-background-image" }, changes: 3, seconds: 10, }, terminal: { plugin: { id: "runestone.terminal", repo: "runestone-terminal", tag: "v0.1.11", zip: `${PLUGIN_RELEASES}/RuneStone_Terminal/releases/runestone.terminal-0.1.11.zip` }, nativeKey: "terminal", /** * Both modes use the same names. Native: the ribbon button comes from the feature switch, and the first click loads * the Terminal feature and xterm (src/lib/features/TerminalHost.svelte), so the action includes that load. */ ribbon: ".plugin-ribbon", button: "Terminal", surface: ".xterm", rows: ".xterm-rows", prompt: "PS [A-Za-z]:\\\\", command: '1..10000 | % { "line $_" }', readyText: "line 10000", }, pdf: { plugin: { id: "runestone.pdf-viewer", repo: "runestone-pdf-viewer", tag: "v0.0.5", zip: `${PLUGIN_RELEASES}/RuneStone_PDF_Viewer/releases/runestone.pdf-viewer-0.0.5.zip` }, nativeKey: "pdf", /** * Both modes use the same names. Native: the tree row opens a PDF tab, and the first tab loads the PDF Viewer feature * and PDF.js (src/lib/features/pdf/), so the action includes that load. Each page canvas is an image named "PDF page N", * and the page field is a spin button named "Page number". Enter in the field goes to the page. */ row: '[data-tree-rel="sample.pdf"]', firstPage: "PDF page 1", pageInput: "Page number", target: 25, targetPage: "PDF page 25", }, pm: { plugin: { id: "runestone.pm", repo: "runestone-pm", tag: "v0.2.49", zip: `${PLUGIN_RELEASES}/RuneStone_Project_Management/releases/runestone.pm-0.2.49.zip` }, nativeKey: "pm", /** Where the view opens: `palette`, or `menu:`. */ openIn: { plugin: "menu:Plug-in views", native: "menu:Plug-in views" }, title: "Project Management", card: { plugin: ".pm-card", native: ".pm-card" }, minCards: 50, }, }, }; /** The value of a table entry for `mode`. */ export const pick = (value, mode) => value && typeof value === "object" && !Array.isArray(value) && ("plugin" in value || "native" in value) ? value[mode] : value; const escape = text => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); const starts = text => new RegExp(`^${escape(text)}`); /** Wait until the page has at least `count` elements for `selector`. The predicate is synchronous on purpose. */ export function waitForCount(page, selector, count, timeout = 60000) { return page.waitForFunction(([selector, count]) => document.querySelectorAll(selector).length >= count, [selector, count], { timeout, polling: 100 }); } /** Open a command from the command palette by its exact title. */ export async function runPaletteCommand(page, title) { await page.keyboard.press(TABLE.palette.shortcut); const input = page.getByRole("textbox", { name: TABLE.palette.input, exact: true }); await input.waitFor({ timeout: 10000 }); await input.fill(title); await page.getByRole("button", { name: starts(title) }).first().waitFor({ timeout: 10000 }); await input.press("Enter"); } /** Run a command from the palette or from a ribbon menu. `where` is `palette` or `menu:`. */ export async function runCommand(page, where, title) { if (where === "palette") return runPaletteCommand(page, title); const menu = /^menu:(.+)$/.exec(where)?.[1]; if (!menu) throw new Error(`Unknown command place ${where}.`); await page.locator(".plugin-ribbon").getByRole("button", { name: menu, exact: true }).click(); await page.getByRole("menuitem", { name: starts(title) }).first().click(); } /** * The in-use action of each feature. Each action returns when its ready condition is true. * `ctx` has `mode` and `log`. Some actions return details for the sample. */ export const ACTIONS = { async git(page, { mode }) { const git = TABLE.features.git; await page.getByRole("button", { name: git.navigation, exact: true }).first().click(); await waitForCount(page, pick(git.changeRow, mode), git.changeCount); await page.locator(pick(git.changeFile, mode)).first().click(); await page.getByRole("tab", { name: starts(git.diffTab) }).first().waitFor({ timeout: 30000 }); await page.getByText(git.diffText).first().waitFor({ timeout: 30000 }); await runCommand(page, pick(git.graphCommandIn, mode), git.graphCommand); await page.getByRole("tab", { name: starts(git.graphTab) }).first().waitFor({ timeout: 30000 }); await page.getByText(git.graphText, { exact: true }).first().waitFor({ timeout: 30000 }); return { changeRows: await page.locator(pick(git.changeRow, mode)).count() }; }, async background(page, { mode }) { const background = TABLE.features.background; const property = pick(background.imageProperty, mode); const started = Date.now(); // Count the changes in the page, so a short image does not slip between two Node polls. await page.evaluate(property => { const state = { values: [], times: [] }; const sample = () => { const value = document.body.style.getPropertyValue(property); if (value && value !== state.values.at(-1)) { state.values.push(value); state.times.push(performance.now()); } }; sample(); state.timer = setInterval(sample, 100); window.__rsBackgroundProbe = state; }, property); const timeout = (background.changes + 2) * background.seconds * 1000 + 30000; await page.waitForFunction(changes => (window.__rsBackgroundProbe?.values.length ?? 0) >= changes + 1, background.changes, { timeout, polling: 250 }); const result = await page.evaluate(() => { const state = window.__rsBackgroundProbe; clearInterval(state.timer); return { images: state.values.length, intervalsMs: state.times.slice(1).map((time, index) => Math.round(time - state.times[index])) }; }); return { ...result, waitedMs: Date.now() - started }; }, async terminal(page) { const terminal = TABLE.features.terminal; await page.locator(terminal.ribbon).getByRole("button", { name: terminal.button, exact: true }).click(); await page.locator(terminal.surface).first().waitFor({ timeout: 30000 }); await page.waitForFunction(([rows, prompt]) => new RegExp(prompt).test((document.querySelector(rows)?.textContent ?? "").replace(/\u00a0/g, " ")), [terminal.rows, terminal.prompt], { timeout: 60000, polling: 100 }); await page.locator(terminal.surface).first().click(); await page.keyboard.type(terminal.command); await page.keyboard.press("Enter"); await page.waitForFunction(([rows, text]) => (document.querySelector(rows)?.textContent ?? "").replace(/\u00a0/g, " ").includes(text), [terminal.rows, terminal.readyText], { timeout: 120000, polling: 100 }); }, async pdf(page) { const pdf = TABLE.features.pdf; await page.locator(pdf.row).click(); await page.getByRole("img", { name: pdf.firstPage, exact: true }).waitFor({ timeout: 60000 }); const input = page.getByRole("textbox", { name: pdf.pageInput, exact: true }).or(page.getByRole("spinbutton", { name: pdf.pageInput, exact: true })).first(); await input.fill(String(pdf.target)); await input.press("Enter"); await page.getByRole("img", { name: pdf.targetPage, exact: true }).waitFor({ timeout: 60000 }); }, async pm(page, { mode }) { const pm = TABLE.features.pm; await runCommand(page, pick(pm.openIn, mode), pm.title); await waitForCount(page, pick(pm.card, mode), pm.minCards); return { cards: await page.locator(pick(pm.card, mode)).count() }; }, };