// The Terminal feature: lazy load, copy and paste, the theme and the --rs-ansi-* colors, splits, maximize, profiles, history pickers, // tasks, run file and run selection, Settings → Terminal, the Off prompt, close and reopen, and the terminal window. // The `pty_*` commands are mocks with channels (tests/smoke/_harness/index.mjs). They do not prove real shell behavior. import assert from "node:assert/strict"; import path from "node:path"; import { mockTauri, openPage, outputDir, runSmoke, settle, smokeUrl } from "../_harness/index.mjs"; await runSmoke("features/terminal", async ({ browser }) => { const output = await outputDir("features/terminal"); const shot = name => path.join(output, name); const context = await browser.newContext({ viewport: { width: 1440, height: 1000 } }); await context.grantPermissions(["clipboard-read", "clipboard-write"]); await mockTauri(context, { state: { confirm: "Cancel" }, commands: test => { const workspace = test.workspace({ root: "C:\\smoke-workspace", files: { "notes/welcome.md": "# Working notes\n\nFirst paragraph.\n", "src/hello.py": "print('hello')\n", }, }); test.files = workspace.files; return { ...workspace, pty_profiles: () => [{ id: "powershell", title: "PowerShell", kind: "powershell" }, { id: "cmd", title: "Command Prompt", kind: "cmd" }, { id: "git-bash", title: "Git Bash", kind: "bash" }, { id: "node", title: "JavaScript Debug Terminal", kind: "node" }], settings_open_window: () => null, spelling_menu_install: () => null, "plugin:window|is_maximized": () => false, "plugin:window|destroy": () => null, "plugin:dialog|message": args => { test.state.prompts = [...test.state.prompts ?? [], args.message]; return test.state.confirm; }, }; }, }); const page = await openPage(context); const count = command => page.evaluate(command => window.__TEST__.calls.filter(c => c.command === command).length, command); const waitCount = (command, n) => page.waitForFunction(({ command, n }) => window.__TEST__.calls.filter(c => c.command === command).length === n, { command, n }); const click = name => page.getByRole("button", { name, exact: true }).click(); const menu = name => page.getByRole("menuitem", { name, exact: true }).click(); const writes = () => page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "pty_write").map(c => c.args.data).join("")); const xtermLoaded = target => target.evaluate(() => performance.getEntriesByType("resource").some(entry => /xterm/i.test(entry.name))); const appearance = (target, mode) => target.evaluate(async mode => { const { applyAppearance } = await import("/src/lib/theme/appearance.ts"); applyAppearance({ theme: "default", mode }); }, mode); await page.goto(smokeUrl); await page.getByText("smoke-workspace", { exact: true }).waitFor(); // The Terminal button shows from the static catalog. The feature module and xterm load at the first use. assert.equal(await xtermLoaded(page), false, "xterm does not load at start"); await click("Terminal"); await waitCount("pty_open", 1); const open = await page.evaluate(() => window.__TEST__.calls.find(c => c.command === "pty_open").args); assert.equal(typeof open.page, "string", "Each open sends the page ID"); assert.equal(open.cwd, "C:\\smoke-workspace"); await page.locator(".xterm-rows > div > span").first().waitFor(); assert.equal(await xtermLoaded(page), true); const terminalFont = await page.locator(".xterm-rows > div > span").first().evaluate(element => { const style = getComputedStyle(element); return { family: style.fontFamily, weight: style.fontWeight, size: style.fontSize }; }); assert.equal(terminalFont.weight, "300"); assert.equal(terminalFont.size, "13px"); assert.ok(terminalFont.family.startsWith('"Cascadia Mono"')); // The input before the open finished includes the answer of xterm to the cursor position query. await page.waitForFunction(() => window.__TEST__.calls.some(c => c.command === "pty_write" && /\x1b\[\d+;\d+R/.test(c.args.data))); // Copy: a drag selects without copy, a right-click copies and clears, Ctrl+C copies a selection, and without one it interrupts. await page.evaluate(() => navigator.clipboard.writeText("before selection")); const beforeSelection = await writes(); const firstText = await page.locator(".xterm-rows > div > span").first().boundingBox(); await page.mouse.move(firstText.x + 1, firstText.y + firstText.height / 2); await page.mouse.down(); await page.mouse.move(firstText.x + firstText.width, firstText.y + firstText.height / 2, { steps: 10 }); await page.mouse.up(); assert.ok(await page.locator(".xterm-selection > div").count(), "Mouse drag selects terminal output."); assert.equal(await page.evaluate(() => navigator.clipboard.readText()), "before selection", "Selection does not copy output."); assert.equal(await writes(), beforeSelection, "Selection does not send input to the shell."); await page.locator(".term").first().screenshot({ path: shot("terminal-copy-selection.png") }); await page.evaluate(() => { window.__TEST__.writeText = navigator.clipboard.writeText.bind(navigator.clipboard); navigator.clipboard.writeText = text => new Promise(resolve => { window.__TEST__.finishCopy = async () => { await window.__TEST__.writeText(text); resolve(); }; }); }); await page.mouse.click(firstText.x + 10, firstText.y + firstText.height / 2, { button: "right" }); assert.ok(await page.locator(".xterm-selection > div").count(), "Selection stays until the clipboard write succeeds."); await page.evaluate(() => window.__TEST__.finishCopy()); await page.evaluate(() => { navigator.clipboard.writeText = window.__TEST__.writeText; }); await page.waitForFunction(async () => (await navigator.clipboard.readText()).includes("READY")); await page.waitForFunction(() => !document.querySelector(".xterm-selection > div")); assert.equal(await writes(), beforeSelection, "Right-click copy does not send input to the shell."); await page.evaluate(() => navigator.clipboard.writeText("empty selection")); await page.mouse.click(firstText.x + 10, firstText.y + firstText.height / 2, { button: "right" }); assert.equal(await page.evaluate(() => navigator.clipboard.readText()), "empty selection", "Right-click without selection keeps the clipboard."); await page.mouse.dblclick(firstText.x + 10, firstText.y + firstText.height / 2); await page.evaluate(() => navigator.clipboard.writeText("")); const beforeCopy = await writes(); await page.keyboard.press("Control+c"); await page.waitForFunction(async () => (await navigator.clipboard.readText()).includes("READY")); assert.equal(await writes(), beforeCopy, "Copy does not send an interrupt to the shell."); const beforeInterrupt = await writes(); await page.locator(".xterm-screen").first().click(); await page.keyboard.press("Control+c"); await page.waitForFunction(before => window.__TEST__.calls.filter(c => c.command === "pty_write").map(c => c.args.data).join("").length > before.length, beforeInterrupt); assert.equal((await writes()).slice(beforeInterrupt.length), "\u0003", "Ctrl+C without selection interrupts the shell."); // A denied clipboard write keeps the selection for another try. await page.mouse.dblclick(firstText.x + 10, firstText.y + firstText.height / 2); await page.evaluate(() => { navigator.clipboard.writeText = () => Promise.reject(new Error("Clipboard denied for smoke test")); }); await page.locator(".xterm-screen").first().click({ button: "right" }); await page.getByText("Error: Clipboard denied for smoke test", { exact: true }).waitFor(); assert.ok(await page.locator(".xterm-selection > div").count(), "Failed copy keeps the selection."); await page.evaluate(() => { navigator.clipboard.writeText = window.__TEST__.writeText; }); // The 16 ANSI colors come from the --rs-ansi-* tokens. A token change reaches the open terminal. const id = open.id; await page.evaluate(id => window.__TEST__.pty.output(id, "\x1b[31mANSI-RED\x1b[0m \x1b[94mANSI-BLUE\x1b[0m\r\n"), id); const colorOf = text => page.evaluate(text => { const span = [...document.querySelectorAll(".xterm-rows span")].find(node => node.textContent.includes(text)); return span && getComputedStyle(span).color; }, text); await page.waitForFunction(() => [...document.querySelectorAll(".xterm-rows span")].some(node => node.textContent.includes("ANSI-RED"))); const red = await page.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue("--rs-ansi-red").trim()); assert.ok(red, "The theme defines --rs-ansi-red"); await page.evaluate(() => { document.documentElement.style.setProperty("--rs-ansi-red", "#12ab34"); document.documentElement.style.setProperty("--rs-ansi-bright-blue", "#3456cd"); }); await page.waitForFunction(() => { const color = text => getComputedStyle([...document.querySelectorAll(".xterm-rows span")].find(node => node.textContent.includes(text))).color; return color("ANSI-RED") === "rgb(18, 171, 52)" && color("ANSI-BLUE") === "rgb(52, 86, 205)"; }); await page.evaluate(() => { for (const name of ["--rs-ansi-red", "--rs-ansi-bright-blue"]) document.documentElement.style.removeProperty(name); }); await page.waitForFunction(() => getComputedStyle([...document.querySelectorAll(".xterm-rows span")].find(node => node.textContent.includes("ANSI-RED"))).color !== "rgb(18, 171, 52)"); assert.notEqual(await colorOf("ANSI-RED"), "rgb(18, 171, 52)"); // Selection colors keep their hue and stay at most 65% opaque, in both themes and at two widths. for (const theme of ["light", "dark"]) { await appearance(page, theme); for (const width of [620, 1440]) { await page.setViewportSize({ width, height: 1000 }); await page.locator(".xterm-helper-textarea").first().focus(); const text = await (await page.waitForFunction(() => { const node = [...document.querySelectorAll(".xterm-rows > div > span")].find(node => node.textContent.includes("READY")); const rect = node?.getBoundingClientRect(); return rect?.width ? { x: rect.x, y: rect.y, width: rect.width, height: rect.height } : null; })).jsonValue(); await page.mouse.move(text.x + 1, text.y + text.height / 2); await page.mouse.down(); await page.mouse.move(text.x + text.width, text.y + text.height / 2, { steps: 10 }); await page.mouse.up(); await page.evaluate(() => navigator.clipboard.writeText("")); await page.keyboard.press("Control+Shift+c"); await page.waitForFunction(async () => (await navigator.clipboard.readText()).includes("READY")); const selectionColor = await page.locator(".xterm-selection > div").first().evaluate(node => getComputedStyle(node).backgroundColor); const selectionAlpha = Number(selectionColor.match(/rgba\([^,]+,[^,]+,[^,]+,\s*([\d.]+)\)/)?.[1] ?? 1); assert.ok(selectionAlpha > 0 && selectionAlpha <= 0.65, `Terminal selection keeps transparency: ${selectionColor}`); assert.ok(await page.locator(".xterm-rows .xterm-decoration-top").first().evaluate(node => getComputedStyle(node).backgroundColor === "rgba(0, 0, 0, 0)"), "Selected glyph backgrounds stay transparent."); await page.locator(".term").first().screenshot({ path: shot(`terminal-theme-${theme}-${width}.png`) }); } } for (const [source, expected] of [["#ff8000", [255, 128, 0, 0.647]], ["rgba(0, 255, 128, 0.35)", [0, 255, 128, 0.35]]]) { await page.evaluate(source => document.documentElement.style.setProperty("--rs-selection", source), source); await page.waitForFunction(expected => { const channels = getComputedStyle(document.querySelector(".xterm-selection > div")).backgroundColor.match(/[\d.]+/g).map(Number); return channels.length === 4 && channels.slice(0, 3).every((channel, index) => Math.abs(channel - expected[index]) <= 2) && Math.abs(channels[3] - expected[3]) < 0.005; }, expected); } await page.evaluate(() => document.documentElement.style.removeProperty("--rs-selection")); // The panel surfaces are translucent, the xterm layers are transparent, and the ribbon controls fit at 620 pixels. const surfaces = () => page.evaluate(() => { const alpha = color => { const canvas = document.createElement("canvas"); canvas.width = canvas.height = 1; const context = canvas.getContext("2d"); context.fillStyle = color; context.fillRect(0, 0, 1, 1); return context.getImageData(0, 0, 1, 1).data[3] / 255; }; return Object.fromEntries([".ribbon", ".term", ".xterm", ".xterm-viewport", ".rail", ".pane-label"].map(selector => { const element = document.querySelector(`.dock ${selector}`); if (!element) return [selector, null]; const style = getComputedStyle(element); return [selector, { alpha: alpha(style.backgroundColor), opacity: style.opacity }]; })); }); for (const mode of ["light", "dark"]) { await appearance(page, mode); await settle(page); const colors = await surfaces(); // The ribbon and the panes use the translucent surface tokens, so a background image shows through them. assert.ok(colors[".ribbon"].alpha > 0.5 && colors[".ribbon"].alpha < 1, `ribbon ${colors[".ribbon"].alpha}`); assert.ok(colors[".term"].alpha > 0.5 && colors[".term"].alpha < 1, `term ${colors[".term"].alpha}`); assert.equal(colors[".xterm"].alpha, 0); assert.equal(colors[".xterm-viewport"].alpha, 0); assert.equal(colors[".ribbon"].opacity, "1"); assert.equal(await page.locator(".bottom").evaluate(element => getComputedStyle(element).backgroundColor), "rgba(0, 0, 0, 0)"); for (const width of [620, 1440]) { await page.setViewportSize({ width, height: 800 }); await page.locator(".xterm-helper-textarea").first().focus(); await settle(page); await page.getByRole("button", { name: "Terminal profiles and tasks", exact: true }).focus(); await page.getByRole("tooltip", { name: "Terminal profiles and tasks", exact: true }).waitFor(); const ribbonBounds = await page.locator(".dock .ribbon").boundingBox(); for (const button of await page.locator(".dock .ribbon button").all()) { const bounds = await button.boundingBox(); assert.ok(bounds.x >= ribbonBounds.x && bounds.x + bounds.width <= ribbonBounds.x + ribbonBounds.width + 1); assert.ok(bounds.width >= 28 && bounds.height >= 28); } await page.screenshot({ path: shot(`terminal-translucent-${mode}-${width}.png`) }); } } // Splits, maximize, hide and show without a close, profiles, and kill. await page.setViewportSize({ width: 1440, height: 1000 }); assert.equal(await page.getByRole("navigation", { name: "Terminal list" }).count(), 0); const adjacent = await page.getByRole("button", { name: "New terminal", exact: true }).evaluate(button => { const buttons = [...button.closest(".actions").querySelectorAll("button")]; return buttons[buttons.indexOf(button) + 1]?.getAttribute("aria-label"); }); assert.equal(adjacent, "Terminal profiles and tasks"); await click("Split terminal (Ctrl+Shift+5)"); await waitCount("pty_open", 2); assert.equal(await page.getByRole("navigation", { name: "Terminal list" }).count(), 1); assert.equal(await page.locator(".pane.shown").count(), 2); const original = await page.locator(".pane.shown").first().boundingBox(); await click("Maximize panel"); const enlarged = await page.locator(".pane.shown").first().boundingBox(); assert.ok(enlarged.height > original.height + 100); assert.equal(await count("pty_close"), 0); await page.screenshot({ path: shot("terminal-splits.png") }); await click("Restore panel"); await page.keyboard.press("Control+j"); assert.equal(await count("pty_close"), 0); await page.keyboard.press("Control+j"); assert.equal(await count("pty_open"), 2); await click("Terminal profiles and tasks"); const splitProfile = page.getByRole("menuitem", { name: "Split terminal with profile", exact: true }); await splitProfile.focus(); await page.keyboard.press("ArrowRight"); const profileSubmenu = page.getByRole("menu", { name: "Split terminal with profile", exact: true }); assert(await profileSubmenu.getByRole("menuitem", { name: "PowerShell", exact: true }).evaluate(node => document.activeElement === node)); await page.keyboard.press("ArrowLeft"); assert(await splitProfile.evaluate(node => document.activeElement === node)); await page.keyboard.press("Escape"); assert(await page.getByRole("button", { name: "Terminal profiles and tasks", exact: true }).evaluate(node => document.activeElement === node)); await click("Terminal profiles and tasks"); await page.screenshot({ path: shot("terminal-profiles.png") }); await menu("Command Prompt"); await waitCount("pty_open", 3); assert.equal(await page.locator(".pane.shown").count(), 1); assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "pty_open").at(-1).args.profile), "cmd"); await page.keyboard.press("Control+Shift+5"); await waitCount("pty_open", 4); assert.equal(await page.locator(".pane.shown").count(), 2); await click("Kill terminal"); await waitCount("pty_close", 1); assert.equal(await page.locator(".pane.shown").count(), 1); // OSC 633 and 133 shell integration fills the history pickers. await page.evaluate(() => { const id = window.__TEST__.calls.filter(c => c.command === "pty_open")[2].args.id; const data = `\x1b]633;RSCommand;${btoa("echo history-check")}\x07\x1b]633;RSCwd;${btoa("C:\\two words")}\x07\x1b]133;A\x07C:\\two words>\x1b]133;B\x07`; window.__TEST__.pty.output(id, data); }); await click("More terminal actions"); assert(await page.getByRole("menuitem", { name: "Run the active file", exact: true }).isDisabled()); assert(await page.getByRole("menuitem", { name: "Run selected text", exact: true }).isDisabled()); await page.screenshot({ path: shot("terminal-actions.png") }); await menu("Run a recent command… Ctrl+Alt+R"); await page.getByRole("dialog").getByRole("option", { name: "echo history-check" }).click(); await page.waitForFunction(() => window.__TEST__.calls.some(c => c.command === "pty_write" && c.args.data.includes("echo history-check"))); await page.keyboard.press("Control+g"); await page.getByRole("dialog").getByRole("option", { name: "C:\\two words" }).click(); await page.waitForFunction(() => window.__TEST__.calls.some(c => c.command === "pty_write" && c.args.data.includes('cd /d "C:\\two words"'))); // Settings → Terminal opens Settings. The page does not load xterm, and its changes reach the open panel. await click("Terminal profiles and tasks"); await menu("Terminal settings"); await waitCount("settings_open_window", 1); const settings = await openPage(context); await settings.goto(`${smokeUrl}/?settingsWindow=true`); const dialog = settings.getByRole("dialog", { name: "Settings", exact: true }); await dialog.getByRole("button", { name: "Terminal", exact: true }).click(); await dialog.getByRole("heading", { name: "Terminal", exact: true }).waitFor(); assert.equal(await xtermLoaded(settings), false, "Settings → Terminal does not load xterm"); const fontSize = dialog.getByLabel("Font size", { exact: true }); assert.equal(await fontSize.inputValue(), "13"); await fontSize.fill("40"); await fontSize.press("Enter"); await fontSize.blur(); await dialog.getByText("Choose a whole number from 9 to 28.", { exact: true }).waitFor(); await fontSize.fill("16"); await fontSize.blur(); await settings.waitForFunction(() => window.__TEST__.settings("terminal")?.fontSize === 16); await page.waitForFunction(() => getComputedStyle(document.querySelector(".pane.shown .xterm-rows > div > span")).fontSize === "16px"); for (const mode of ["light", "dark"]) { await appearance(settings, mode); for (const width of [1152, 360]) { await settings.setViewportSize({ width, height: width === 360 ? 640 : 815 }); await settle(settings); assert(await settings.evaluate(() => document.documentElement.scrollWidth <= innerWidth), `No horizontal scroll at ${width} pixels`); await settings.screenshot({ path: shot(`settings-terminal-${mode}-${width}.png`) }); } await dialog.getByRole("button", { name: "Default profile", exact: true }).click(); const profileMenu = settings.getByRole("menu", { name: "Default terminal profile", exact: true }); const current = profileMenu.getByRole("menuitemradio", { name: "PowerShell", exact: true }); assert.equal(await current.getAttribute("aria-checked"), "true"); assert.equal(await profileMenu.getByRole("menuitemradio", { name: "JavaScript Debug Terminal", exact: true }).count(), 0, "The debug terminal is not a default"); const bounds = await profileMenu.boundingBox(); assert(bounds.x >= 0 && bounds.x + bounds.width <= 360 && bounds.y >= 0 && bounds.y + bounds.height <= 640); await settings.screenshot({ path: shot(`settings-terminal-profile-${mode}-360.png`) }); await settings.keyboard.press("End"); assert(await profileMenu.getByRole("menuitemradio", { name: "Git Bash", exact: true }).evaluate(node => document.activeElement === node)); await settings.keyboard.press("Escape"); assert(await dialog.getByRole("button", { name: "Default profile", exact: true }).evaluate(node => document.activeElement === node)); } await settings.setViewportSize({ width: 1152, height: 815 }); await dialog.getByRole("button", { name: "Default profile", exact: true }).click(); await settings.getByRole("menuitemradio", { name: "Git Bash", exact: true }).click(); await dialog.getByRole("switch", { name: "Blink cursor", exact: true }).uncheck(); await settings.waitForFunction(() => window.__TEST__.settings("terminal")?.defaultProfile === "git-bash" && window.__TEST__.settings("terminal")?.cursorBlink === false); await page.bringToFront(); await click("New terminal"); await waitCount("pty_open", 5); assert.equal(await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "pty_open").at(-1).args.profile), "git-bash"); // Tasks from .runestone/tasks.json, with the shared picker rows at 360 pixels in both themes. await page.evaluate(() => window.__TEST__.files.set(".runestone/tasks.json", JSON.stringify({ tasks: [{ label: "Smoke task", command: "echo task-ok", profile: "powershell" }] }))); await click("Terminal profiles and tasks"); await menu("Run a task…"); for (const mode of ["light", "dark"]) { await appearance(page, mode); await page.setViewportSize({ width: 360, height: 640 }); const row = page.getByRole("option", { name: "Smoke task echo task-ok" }); const measurements = await row.evaluate(node => { const css = getComputedStyle(node); const root = getComputedStyle(document.documentElement); return { fontSize: css.fontSize, minHeight: css.minHeight, padding: css.padding, radius: css.borderRadius, tokenFont: root.getPropertyValue("--rs-menu-font-size").trim(), tokenHeight: root.getPropertyValue("--rs-menu-row-height").trim(), tokenRadius: root.getPropertyValue("--rs-control-radius").trim(), tokenPadding: root.getPropertyValue("--rs-menu-row-padding").trim() }; }); assert.equal(measurements.fontSize, measurements.tokenFont); assert.equal(measurements.minHeight, measurements.tokenHeight); assert.equal(measurements.radius, measurements.tokenRadius); assert.equal(measurements.padding, measurements.tokenPadding); await page.screenshot({ path: shot(`terminal-task-picker-${mode}-360.png`) }); } await page.setViewportSize({ width: 1440, height: 1000 }); const taskQuery = page.getByRole("combobox", { name: "Run a task", exact: true }); await taskQuery.fill("no-such-task"); await page.getByText("No entries match the filter.", { exact: true }).waitFor(); assert.equal(await page.getByRole("option").count(), 0); await taskQuery.fill("Smoke task"); const taskOption = page.getByRole("option", { name: "Smoke task echo task-ok" }); assert.equal(await taskQuery.getAttribute("aria-activedescendant"), await taskOption.getAttribute("id")); await taskQuery.press("Enter"); await waitCount("pty_open", 6); await page.waitForFunction(() => window.__TEST__.calls.some(c => c.command === "pty_write" && c.args.data.includes("echo task-ok"))); // Run selected text and run the active file. The editor keeps its selection while the menu takes focus. // The shell owns its control keys, so the test opens the file from a new tab. await click("New tab (Ctrl+T)"); await page.getByRole("button", { name: /^Find file/ }).click(); await page.getByRole("textbox", { name: "Find a file" }).fill("hello.py"); await page.getByRole("dialog").getByRole("button").filter({ hasText: "hello.py" }).first().click(); const editor = page.locator(".cm-content").first(); await editor.waitFor(); const editorFont = await editor.evaluate(element => ({ family: getComputedStyle(element).fontFamily, weight: getComputedStyle(element).fontWeight })); assert.equal(editorFont.weight, terminalFont.weight, "The terminal uses the code font weight"); assert.ok(editorFont.family.startsWith(terminalFont.family.split(",")[0]), "The terminal uses the code font"); await editor.click(); await page.keyboard.press("Control+a"); await click("More terminal actions"); await menu("Run selected text"); await page.waitForFunction(() => window.__TEST__.calls.some(c => c.command === "pty_write" && c.args.data.includes("print('hello')"))); await click("More terminal actions"); await menu("Run the active file"); await page.waitForFunction(() => window.__TEST__.calls.some(c => c.command === "pty_write" && c.args.data.includes("python 'C:\\smoke-workspace\\src\\hello.py'"))); await click("Terminal profiles and tasks"); await menu("New terminal window Ctrl+Alt+Shift+`"); await waitCount("pty_new_window", 1); await click("More terminal actions"); await menu("Start dictation"); await waitCount("pty_dictation", 1); await click("More terminal actions"); await menu("Clear the terminal"); assert.equal(await count("pty_close"), 1); // Kill down to one session and none, start again, the new and window shortcuts, then close and a fresh reopen. await page.setViewportSize({ width: 880, height: 600 }); await page.screenshot({ path: shot("terminal-narrow.png") }); for (let remaining = 5; remaining > 1; remaining--) await click("Kill terminal"); await waitCount("pty_close", 5); assert.equal(await page.getByRole("navigation", { name: "Terminal list" }).count(), 0); await click("Kill terminal"); await waitCount("pty_close", 6); await click("Start a terminal"); await waitCount("pty_open", 7); await page.locator(".pane.shown .xterm-helper-textarea").focus(); await page.keyboard.press("Control+Shift+Backquote"); await waitCount("pty_open", 8); await page.keyboard.press("Control+Shift+Alt+Backquote"); await waitCount("pty_new_window", 2); const opens = await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "pty_open").map(c => c.args.id)); await click("Close terminal (end all sessions)"); await waitCount("pty_close", opens.length); const closedIds = await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "pty_close").map(c => c.args.id)); assert.deepEqual([...closedIds].sort(), [...opens].sort()); await page.keyboard.press("Control+j"); await waitCount("pty_open", opens.length + 1); const freshId = await page.evaluate(() => window.__TEST__.calls.filter(c => c.command === "pty_open").at(-1).args.id); assert.equal(opens.includes(freshId), false); // The new shell takes the focus when it starts. Wait for that before the focus moves to the close button. await page.waitForFunction(id => window.__TEST__.calls.some(c => c.command === "pty_resize" && c.args.id === id), freshId); await appearance(page, "light"); await settle(page); await page.getByRole("button", { name: "Close terminal (end all sessions)", exact: true }).focus(); await page.getByRole("tooltip", { name: "Close terminal (end all sessions)", exact: true }).waitFor(); await page.screenshot({ path: shot("terminal-close-light-narrow-focus.png") }); await page.keyboard.press("Enter"); await waitCount("pty_close", opens.length + 1); await page.keyboard.press("Control+Shift+Backquote"); await waitCount("pty_open", opens.length + 2); assert.equal(await page.locator(".pane.shown").count(), 1); // Off asks first while a shell runs. Cancel keeps the shells. OK ends them and removes the controls. await settings.bringToFront(); await dialog.getByRole("button", { name: "Features", exact: true }).click(); const terminalSwitch = dialog.getByRole("switch", { name: "Terminal", exact: true }); await terminalSwitch.click(); await settings.waitForFunction(() => window.__TEST__.state.prompts?.length === 1); await settings.waitForFunction(() => document.querySelector("#feature-terminal").checked); assert.deepEqual(await settings.evaluate(() => window.__TEST__.state.prompts), ["Terminal sessions will end.\nTurn off Terminal?"]); assert.equal(await terminalSwitch.isChecked(), true, "Cancel keeps Terminal on"); assert.equal(await settings.evaluate(() => window.__TEST__.settings("features").terminal), true); const closesBefore = await count("pty_close"); await settings.evaluate(() => { window.__TEST__.state.confirm = "Ok"; }); await terminalSwitch.click(); await page.waitForFunction(before => window.__TEST__.calls.filter(c => c.command === "pty_close").length > before, closesBefore); assert.equal(await settings.evaluate(() => window.__TEST__.settings("features").terminal), false); await page.getByRole("button", { name: "Terminal", exact: true }).waitFor({ state: "detached" }); assert.equal(await dialog.getByRole("button", { name: "Terminal", exact: true }).count(), 0, "Settings → Terminal hides while Terminal is off"); for (const mode of ["light", "dark"]) { await appearance(settings, mode); await settings.setViewportSize({ width: 360, height: 640 }); await settle(settings); await settings.screenshot({ path: shot(`features-terminal-off-${mode}-360.png`) }); } // Without prompts, an Off with no shell needs no question. await terminalSwitch.check(); await page.getByRole("button", { name: "Terminal", exact: true }).first().waitFor(); await settings.evaluate(() => { window.__TEST__.state.prompts = []; }); await terminalSwitch.uncheck(); await settings.waitForFunction(() => window.__TEST__.settings("features").terminal === false); assert.deepEqual(await settings.evaluate(() => window.__TEST__.state.prompts), []); await terminalSwitch.check(); assert.deepEqual([...page.errors, ...settings.errors], []); await settings.close(); // The terminal window: one session, no workspace open, the exit code from the channel, and close. await page.goto(`${smokeUrl}/?terminalWindow=C%3A%5Csmoke-workspace`); await page.locator(".xterm").waitFor(); await waitCount("pty_open", 1); assert.equal(await count("workspace_open"), 0); assert.equal(await page.getByRole("button", { name: "Close terminal window", exact: true }).count(), 1); assert.equal(await page.getByRole("button", { name: "Maximize panel", exact: true }).count(), 0); await page.screenshot({ path: shot("terminal-window.png") }); await page.evaluate(() => window.__TEST__.pty.exit(window.__TEST__.calls.find(c => c.command === "pty_open").args.id, 3)); await page.waitForFunction(() => document.querySelector(".xterm-rows")?.textContent.includes("[Process exited with code 3]")); await click("Close terminal window"); await waitCount("plugin:window|destroy", 1); assert.equal(await count("pty_close"), 0, "The host removed the exited shell, so the close needs no host call"); assert.deepEqual(page.errors, []); console.log("PASS: terminal lazy load, copy, ANSI tokens, selection, splits, profiles, history, Settings → Terminal, tasks, run file, Off prompt, close and reopen, and the terminal window."); }, { timeout: 30000 });