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:
Knotty Wyvern
2026-10-27 20:58:55 -07:00
parent c66ea1ce83
commit 69f90df571
109 changed files with 5920 additions and 7915 deletions
+44 -54
View File
@@ -1,48 +1,37 @@
// Character theme typography: CSS families and the fonts Chromium renders for UI, prose, headings, and code, plus narrow settings.
import assert from 'node:assert/strict';
import { mkdir, writeFile } from 'node:fs/promises';
import { createRequire } from 'node:module';
import { writeFile } from 'node:fs/promises';
import path from 'node:path';
import { mockTauri, openPage, outputDir, runSmoke, settle, smokeUrl } from '../_harness/index.mjs';
const { chromium } = createRequire(import.meta.url)(process.env.PLAYWRIGHT_MODULE || 'playwright');
const origin = process.env.SMOKE_URL || 'http://127.0.0.1:1420';
const output = '.audit/theme-typography';
const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) });
const errors = [];
const report = [];
await mkdir(output, { recursive: true });
try {
await runSmoke('appearance/typography', async ({ browser }) => {
const output = await outputDir('appearance/typography');
const report = [];
const context = await browser.newContext({ viewport: { width: 1100, height: 780 } });
await context.addInitScript(() => {
window.isTauri = true;
window.__TAURI_INTERNALS__ = {
metadata: { currentWindow: { label: 'main' }, currentWebview: { label: 'main' } },
transformCallback: () => 1, unregisterCallback: () => {},
invoke: async (command, args = {}) => {
if (command === 'plugins_snapshot') return { root: 'C:/font-smoke-plugins', plugins: [] };
if (command === 'workspace_last_path') return 'C:\\font-smoke';
if (command === 'workspace_open') return { root: 'C:\\font-smoke', name: 'font-smoke', watch_mode: 'native' };
if (command === 'workspace_list') return [{ name: 'Typography.md', rel_path: 'Typography.md', kind: 'file' }];
if (command === 'workspace_read') return '# A place for your ideas\n\nRead the next chapter, collect clear notes, and keep your work close. Small letters, open spaces, and steady lines help each sentence stay readable.\n\n## Details worth keeping\n\nThe quick brown fox jumps over the lazy dog. Il1 O0 rn m, 0123456789.\n\n`const name = "RuneStone";`\n';
if (command === 'workspace_search') return [];
if (command === 'plugin:event|listen') return args.handler;
return null;
},
};
window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener: () => {} };
await mockTauri(context, {
commands: test => ({
...test.workspace({
root: 'C:\\font-smoke',
files: { 'Typography.md': '# A place for your ideas\n\nRead the next chapter, collect clear notes, and keep your work close. Small letters, open spaces, and steady lines help each sentence stay readable.\n\n## Details worth keeping\n\nThe quick brown fox jumps over the lazy dog. Il1 O0 rn m, 0123456789.\n\n`const name = "RuneStone";`\n' },
}),
plugins_snapshot: () => ({ root: 'C:/font-smoke-plugins', plugins: [] }),
}),
});
const main = await context.newPage();
const settings = await context.newPage();
for (const page of [main, settings]) page.on('pageerror', error => errors.push(error.message));
await main.goto(origin);
const main = await openPage(context);
const settings = await openPage(context);
await main.goto(smokeUrl);
await main.getByText('font-smoke', { exact: true }).waitFor();
await main.keyboard.press('Control+p');
await main.getByRole('textbox', { name: 'Find a file' }).fill('Typography.md');
await main.getByRole('textbox', { name: 'Find a file' }).press('Enter');
await main.getByRole('textbox', { name: 'Writing editor', exact: true }).waitFor();
await settings.goto(`${origin}/?settingsWindow=true`);
await settings.goto(`${smokeUrl}/?settingsWindow=true`);
await settings.getByRole('button', { name: 'Appearance', exact: true }).click();
const sessions = new Map();
// The CSS font of `selector` and the platform fonts Chromium used to draw its glyphs.
async function rendered(page, selector) {
await page.evaluate(() => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve))));
await settle(page);
let session = sessions.get(page);
if (!session) {
session = await context.newCDPSession(page);
@@ -58,6 +47,11 @@ try {
});
return { ...style, rendered: fonts.filter(font => font.glyphCount).map(({ familyName, postScriptName, glyphCount, isCustomFont }) => ({ familyName, postScriptName, glyphCount, isCustomFont })) };
}
const setPluginTools = count => settings.evaluate(async count => {
const { pluginTools } = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name);
pluginTools.set(Array.from({ length: count }, (_, index) => ({ owner: 'org.example.font-check', id: `settings-${index}`, title: `Plugin settings ${index + 1}`, surface: 'settings' })));
}, count);
const selectors = { ui: '.picker[aria-label="Color theme"]', prose: '.cm-line:not(.writer-heading):not(.writer-blank)', heading: '.writer-h1' };
const cases = [
['harvest-moon', 'Harvest Moon', 'Constantia', 'Candara', 'Constantia', 'Constantia'],
['crimson-pilot', 'Crimson Pilot', 'Bahnschrift', 'Bahnschrift', 'Segoe UI', 'Bahnschrift'],
@@ -75,15 +69,15 @@ try {
await page.evaluate(font => {
for (const role of ['ui', 'prose', 'heading']) document.documentElement.style.setProperty(`--rs-font-${role}`, `"${font}"`);
}, oldFont);
await page.screenshot({ path: `${output}/${theme}-before-${page === main ? 'document' : 'settings'}.png` });
await page.screenshot({ path: path.join(output, `${theme}-before-${page === main ? 'document' : 'settings'}.png`) });
await page.evaluate(() => {
for (const role of ['ui', 'prose', 'heading']) document.documentElement.style.removeProperty(`--rs-font-${role}`);
});
}
const roles = {
ui: await rendered(settings, '.picker[aria-label="Color theme"]'),
prose: await rendered(main, '.cm-line:not(.writer-heading):not(.writer-blank)'),
heading: await rendered(main, '.writer-h1'),
ui: await rendered(settings, selectors.ui),
prose: await rendered(main, selectors.prose),
heading: await rendered(main, selectors.heading),
mono: await rendered(settings, '.preview-code'),
};
for (const [role, family] of Object.entries({ ui, prose, heading })) {
@@ -94,8 +88,8 @@ try {
assert.equal(roles.prose.size, '15px');
assert(roles.mono.family.includes('Cascadia Mono'));
assert(roles.mono.rendered.some(font => font.familyName === 'Cascadia Mono'));
await settings.screenshot({ path: `${output}/${theme}-after-settings.png` });
await main.screenshot({ path: `${output}/${theme}-after-document.png` });
await settings.screenshot({ path: path.join(output, `${theme}-after-settings.png`) });
await main.screenshot({ path: path.join(output, `${theme}-after-document.png`) });
await main.getByRole('textbox', { name: 'Writing editor', exact: true }).evaluate(node => {
node.focus();
const paragraph = [...node.querySelectorAll('.cm-line')].find(line => line.textContent.includes('Read the next chapter'));
@@ -103,7 +97,7 @@ try {
const selection = window.getSelection(); selection.removeAllRanges(); selection.addRange(range);
});
assert((await main.evaluate(() => getSelection().toString())).includes('Read the next chapter'));
await main.screenshot({ path: `${output}/${theme}-selected-prose.png` });
await main.screenshot({ path: path.join(output, `${theme}-selected-prose.png`) });
await settings.setViewportSize({ width: 360, height: 480 });
const content = settings.locator('dialog .content');
assert(await content.evaluate(node => node.scrollWidth <= node.clientWidth), `${theme}: narrow overflow`);
@@ -111,35 +105,31 @@ try {
const current = settings.getByRole('menuitemradio', { name: label, exact: true });
await current.waitFor();
assert(await current.evaluate(node => node === document.activeElement));
await settings.screenshot({ path: `${output}/${theme}-narrow-menu.png` });
await settings.screenshot({ path: path.join(output, `${theme}-narrow-menu.png`) });
await settings.keyboard.press('Escape');
assert(await picker.evaluate(node => node === document.activeElement));
await settings.evaluate(async () => {
const { pluginTools } = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name);
pluginTools.set(Array.from({ length: 16 }, (_, index) => ({ owner: 'org.example.font-check', id: `settings-${index}`, title: `Plugin settings ${index + 1}`, surface: 'settings' })));
});
await setPluginTools(16);
const bodyBounds = await settings.locator('dialog .body').boundingBox();
assert((await settings.locator('dialog aside').boundingBox()).height <= bodyBounds.height * .4 + 1);
await settings.getByRole('button', { name: 'Plugin settings 16', exact: true }).scrollIntoViewIfNeeded();
assert(await content.evaluate(node => node.scrollWidth <= node.clientWidth));
await settings.screenshot({ path: `${output}/${theme}-narrow-long-plugins.png` });
await settings.evaluate(async () => {
const { pluginTools } = await import(performance.getEntriesByType('resource').find(entry => new URL(entry.name).pathname === '/src/lib/plugins/external.ts').name); pluginTools.set([]);
});
await settings.screenshot({ path: path.join(output, `${theme}-narrow-long-plugins.png`) });
await setPluginTools(0);
// Drop the first family from each stack and check that the fallback still renders glyphs.
const fallback = {};
for (const [role, page, selector] of [['ui', settings, '.picker[aria-label="Color theme"]'], ['prose', main, '.cm-line:not(.writer-heading):not(.writer-blank)'], ['heading', main, '.writer-h1']]) {
for (const [role, page] of [['ui', settings], ['prose', main], ['heading', main]]) {
await page.evaluate(role => {
const css = getComputedStyle(document.documentElement);
const stack = css.getPropertyValue(`--rs-font-${role}`);
document.documentElement.style.setProperty(`--rs-font-${role}`, stack.slice(stack.indexOf(',') + 1));
}, role);
fallback[role] = await rendered(page, selector);
fallback[role] = await rendered(page, selectors[role]);
assert(fallback[role].rendered.length > 0);
await page.evaluate(role => document.documentElement.style.removeProperty(`--rs-font-${role}`), role);
}
report.push({ theme, oldFont, roles, fallback });
console.log(`PASS ${theme}: real UI and prose sizes, rendered fonts, shared monospace, selection, narrow settings, keyboard focus, long plugin navigation`);
}
assert.deepEqual(errors, []);
await writeFile(`${output}/rendered-fonts.json`, JSON.stringify(report, null, 2));
} finally { await browser.close(); }
assert.deepEqual([...main.errors, ...settings.errors], []);
await writeFile(path.join(output, 'rendered-fonts.json'), JSON.stringify(report, null, 2));
});