Update editor, workspace, Git services, appearance, and project guides
This commit is contained in:
@@ -0,0 +1,199 @@
|
||||
// Run against the development server with an isolated browser storage context.
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdir } from "node:fs/promises";
|
||||
import { createRequire } from "node:module";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const { chromium } = require(process.env.PLAYWRIGHT_MODULE || "playwright");
|
||||
const origin = process.env.SMOKE_URL || "http://127.0.0.1:1420";
|
||||
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
|
||||
const errors = [];
|
||||
const findings = [];
|
||||
const output = ".audit";
|
||||
await mkdir(output, { recursive: true });
|
||||
try {
|
||||
const context = await browser.newContext({ viewport: { width: 1100, height: 780 } });
|
||||
await context.addInitScript(() => {
|
||||
window.isTauri = true;
|
||||
const root = "C:\\appearance-smoke";
|
||||
const files = new Map(Array.from({ length: 12 }, (_, index) => [`theme-${index}.py`, `# Theme sample ${index}\ndef sample(parameter):\n return parameter\nname = "RuneStone"\nprint(name, 42)\n`]));
|
||||
const callbacks = new Map();
|
||||
let sequence = 0;
|
||||
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 = {}) => {
|
||||
if (command === "plugins_snapshot") return { root: "C:/appearance-smoke-plugins", plugins: [] };
|
||||
if (command === "workspace_last_path") return root;
|
||||
if (command === "workspace_open") return { root, name: "appearance-smoke", watch_mode: "native" };
|
||||
if (command === "workspace_read") { if (!files.has(args.rel)) throw new Error("File absent"); return files.get(args.rel); }
|
||||
if (command === "workspace_write") { files.set(args.rel, args.contents); return; }
|
||||
if (command === "workspace_list") return [...files.keys()].filter(path => !path.startsWith(".")).map(path => ({ name: path, rel_path: path, kind: "file" }));
|
||||
if (command === "workspace_search") return [];
|
||||
if (command === "plugin:event|listen") return args.handler;
|
||||
if (command === "plugin:window|is_maximized") return false;
|
||||
return null;
|
||||
},
|
||||
};
|
||||
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
|
||||
});
|
||||
const main = await context.newPage();
|
||||
const settings = await context.newPage();
|
||||
const secondSettings = await context.newPage();
|
||||
for (const page of [main, settings, secondSettings]) {
|
||||
page.setDefaultTimeout(10000);
|
||||
page.on("pageerror", error => errors.push(error.message));
|
||||
}
|
||||
await main.goto(origin);
|
||||
await main.getByText("appearance-smoke", { exact: true }).waitFor();
|
||||
async function openCode(index) {
|
||||
await main.keyboard.press("Control+p");
|
||||
await main.getByRole("textbox", { name: "Find a file" }).fill(`theme-${index}.py`);
|
||||
await main.getByRole("dialog").getByRole("button").filter({ hasText: `theme-${index}.py` }).first().waitFor();
|
||||
await main.getByRole("textbox", { name: "Find a file" }).press("Enter");
|
||||
await main.locator(".monaco-editor textarea").waitFor();
|
||||
await main.waitForFunction(async file => {
|
||||
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
|
||||
return monaco.editor.getEditors().some(editor => editor.getDomNode()?.isConnected && editor.getModel()?.uri.path.endsWith(file));
|
||||
}, `theme-${index}.py`);
|
||||
await main.locator(".view-line").filter({ hasText: `Theme sample ${index}` }).waitFor();
|
||||
}
|
||||
async function editorIds() {
|
||||
return main.evaluate(async () => {
|
||||
const { monaco } = await import("/src/lib/editor/monacoEnv.ts");
|
||||
return monaco.editor.getEditors().filter(editor => editor.getDomNode()?.isConnected).map(editor => editor.getId());
|
||||
});
|
||||
}
|
||||
async function syntaxColors() {
|
||||
return main.locator(".view-line span").evaluateAll(spans => Object.fromEntries(["RuneStone", "print", "42"].map(text => {
|
||||
const span = spans.find(node => !node.children.length && node.textContent.includes(text));
|
||||
return [text, span ? getComputedStyle(span).color : null];
|
||||
})));
|
||||
}
|
||||
async function waitForSyntax(expected = null) {
|
||||
await main.waitForFunction(expected => {
|
||||
const spans = [...document.querySelectorAll(".view-line span")];
|
||||
const colors = Object.fromEntries(["RuneStone", "print", "42"].map(text => {
|
||||
const span = spans.find(node => !node.children.length && node.textContent.includes(text));
|
||||
return [text, span ? getComputedStyle(span).color : null];
|
||||
}));
|
||||
return expected ? JSON.stringify(colors) === JSON.stringify(expected) : Object.values(colors).every(Boolean) && new Set(Object.values(colors)).size === 3;
|
||||
}, expected);
|
||||
}
|
||||
async function openAppearance(page) {
|
||||
await page.goto(`${origin}/?settingsWindow=true`);
|
||||
await page.getByRole("button", { name: "Appearance", exact: true }).click();
|
||||
await page.getByRole("combobox", { name: "Color theme", exact: true }).waitFor();
|
||||
}
|
||||
await openCode(0);
|
||||
await openAppearance(settings);
|
||||
await openAppearance(secondSettings);
|
||||
async function expectAppearance(theme, mode) {
|
||||
for (const page of [settings, secondSettings, main]) {
|
||||
await page.waitForFunction(({ theme, mode }) => document.documentElement.dataset.palette === theme && document.documentElement.dataset.theme === mode, { theme, mode });
|
||||
assert.equal(await page.evaluate(() => getComputedStyle(document.documentElement).colorScheme), mode);
|
||||
}
|
||||
assert.equal(await secondSettings.getByRole("combobox", { name: "Color theme", exact: true }).inputValue(), theme);
|
||||
assert.equal(await secondSettings.getByRole("combobox", { name: "Appearance", exact: true }).inputValue(), mode);
|
||||
await main.waitForFunction(() => {
|
||||
const root = document.documentElement;
|
||||
const probe = document.createElement("i");
|
||||
probe.style.backgroundColor = getComputedStyle(root).getPropertyValue("--rs-bg");
|
||||
document.body.append(probe);
|
||||
const expected = getComputedStyle(probe).backgroundColor;
|
||||
probe.remove();
|
||||
const surfaces = [...document.querySelectorAll(".monaco-editor .monaco-editor-background")];
|
||||
return surfaces.length > 0 && surfaces.every(element => getComputedStyle(element).backgroundColor === expected);
|
||||
});
|
||||
return settings.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue("--rs-bg").trim());
|
||||
}
|
||||
let nextCode = 1;
|
||||
const backgrounds = new Set();
|
||||
|
||||
for (const theme of ["default", "claude", "sakura"]) {
|
||||
for (const mode of theme === "sakura" ? ["light"] : ["light", "dark"]) {
|
||||
const before = await editorIds();
|
||||
await settings.getByRole("combobox", { name: "Color theme", exact: true }).selectOption(theme);
|
||||
if (theme !== "sakura") await settings.getByRole("combobox", { name: "Appearance", exact: true }).selectOption(mode);
|
||||
backgrounds.add(await expectAppearance(theme, mode));
|
||||
assert.deepEqual(await editorIds(), before, "Existing Monaco editors keep their identity when a theme changes");
|
||||
await openCode(nextCode++);
|
||||
assert.notDeepEqual(await editorIds(), before, "A new file creates a new Monaco editor");
|
||||
await expectAppearance(theme, mode);
|
||||
await waitForSyntax();
|
||||
assert.deepEqual(await settings.evaluate(() => JSON.parse(localStorage.getItem("runestone.appearance"))), { theme, mode });
|
||||
await settings.screenshot({ path: `${output}/appearance-${theme}-${mode}.png` });
|
||||
await main.screenshot({ path: `${output}/appearance-editor-${theme}-${mode}.png` });
|
||||
if (theme === 'sakura') {
|
||||
const keywordColor = await main.locator('.view-line span').evaluateAll(spans => {
|
||||
const keyword = spans.find(span => !span.children.length && span.textContent.trim() === 'def');
|
||||
return keyword ? getComputedStyle(keyword).color : null;
|
||||
});
|
||||
assert.equal(keywordColor, 'rgb(152, 85, 108)', 'Sakura keywords use Plum Wine');
|
||||
}
|
||||
const typography = await settings.evaluate(() => ({
|
||||
body: getComputedStyle(document.body).fontFamily,
|
||||
heading: getComputedStyle(document.querySelector('h2')).fontFamily,
|
||||
prose: getComputedStyle(document.documentElement).getPropertyValue('--rs-font-prose').trim(),
|
||||
}));
|
||||
if (theme === 'claude') {
|
||||
assert.match(typography.body, /Lora.*Georgia/);
|
||||
assert.match(typography.prose, /Lora.*Georgia/);
|
||||
assert.match(typography.heading, /Poppins.*Arial/);
|
||||
assert.equal(await settings.evaluate(() => getComputedStyle(document.documentElement).getPropertyValue('--rs-accent').trim()), '#d97757');
|
||||
} else assert.doesNotMatch(typography.body, /Lora|Georgia/);
|
||||
console.log(`PASS: ${theme} ${mode}, saved state, cross-window selection, existing and new Monaco editors`);
|
||||
}
|
||||
}
|
||||
assert.equal(backgrounds.size, 5, "All supported combinations have distinct backgrounds");
|
||||
assert.deepEqual(await settings.getByRole('combobox', { name: 'Color theme', exact: true }).locator('option').evaluateAll(options => options.map(option => option.value)), ['default', 'claude', 'sakura']);
|
||||
assert.equal(await settings.getByRole('combobox', { name: 'Appearance', exact: true }).isDisabled(), true);
|
||||
assert.equal(await secondSettings.getByRole('combobox', { name: 'Appearance', exact: true }).isDisabled(), true);
|
||||
const sakura = await settings.evaluate(() => {
|
||||
const css = getComputedStyle(document.documentElement);
|
||||
return Object.fromEntries(['bg', 'border', 'selection', 'bg-active', 'syntax-parameter', 'syntax-keyword', 'syntax-local', 'syntax-static', 'syntax-instance', 'syntax-global'].map(key => [key, css.getPropertyValue(`--rs-${key}`).trim()]));
|
||||
});
|
||||
assert.deepEqual(sakura, { bg: '#fefcfc', border: '#f8dbe6', selection: '#ffc9dc', 'bg-active': '#dbeacb', 'syntax-parameter': '#cb6b91', 'syntax-keyword': '#98556c', 'syntax-local': '#618c71', 'syntax-static': '#69a2bd', 'syntax-instance': '#607fa9', 'syntax-global': '#687788' });
|
||||
for (const [theme, savedMode, expectedTheme, mode] of [
|
||||
['gpt', 'light', 'default', 'light'],
|
||||
['terminal', 'dark', 'default', 'dark'],
|
||||
['sakura', 'dark', 'sakura', 'light'],
|
||||
]) {
|
||||
await settings.evaluate(value => localStorage.setItem('runestone.appearance', JSON.stringify(value)), { theme, mode: savedMode });
|
||||
await settings.reload();
|
||||
await settings.getByRole('button', { name: 'Appearance', exact: true }).click();
|
||||
await expectAppearance(expectedTheme, mode);
|
||||
assert.deepEqual(await settings.evaluate(() => JSON.parse(localStorage.getItem('runestone.appearance'))), { theme: expectedTheme, mode });
|
||||
console.log(`PASS: saved ${theme} ${savedMode} migrates to ${expectedTheme} ${mode}`);
|
||||
}
|
||||
for (const [theme, mode] of [['default', 'dark'], ['claude', 'light'], ['claude', 'dark'], ['sakura', 'light']]) {
|
||||
await settings.setViewportSize({ width: 1100, height: 780 });
|
||||
await settings.getByRole('combobox', { name: 'Color theme', exact: true }).selectOption(theme);
|
||||
if (theme !== 'sakura') await settings.getByRole('combobox', { name: 'Appearance', exact: true }).selectOption(mode);
|
||||
await expectAppearance(theme, mode);
|
||||
await settings.setViewportSize({ width: 360, height: 480 });
|
||||
assert(await settings.evaluate(() => document.documentElement.scrollWidth <= innerWidth), 'Narrow settings do not overflow the viewport');
|
||||
const content = settings.locator('dialog .content');
|
||||
assert(await content.evaluate(node => node.scrollWidth <= node.clientWidth), 'Appearance controls do not overflow the content area');
|
||||
for (const name of ['Color theme', 'Appearance']) {
|
||||
const control = settings.getByRole('combobox', { name, exact: true });
|
||||
await control.scrollIntoViewIfNeeded();
|
||||
const bounds = await control.boundingBox();
|
||||
assert(bounds.x >= 0 && bounds.x + bounds.width <= 360 && bounds.height >= 28, `${name} remains reachable at 360px`);
|
||||
}
|
||||
await settings.screenshot({ path: `${output}/appearance-${theme}-${mode}-360.png` });
|
||||
}
|
||||
assert.deepEqual(errors, []);
|
||||
assert.deepEqual(findings, [], 'Appearance findings');
|
||||
await context.close();
|
||||
console.log('Appearance smoke passed: supported palettes, modes, light-only Sakura, migration, persistence, typography, cross-window sync, Monaco updates, and narrow settings.');
|
||||
} catch (error) {
|
||||
console.error('Browser errors:', errors);
|
||||
for (const [index, page] of browser.contexts().flatMap(context => context.pages()).entries()) {
|
||||
await page.screenshot({ path: `${output}/appearance-failure-${index}.png` }).catch(() => {});
|
||||
}
|
||||
throw error;
|
||||
} finally { await browser.close(); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user