import assert from 'node:assert/strict'; import { mkdir, writeFile } from 'node:fs/promises'; import { createRequire } from 'node:module'; const { chromium } = createRequire(import.meta.url)(process.env.PLAYWRIGHT_MODULE || 'playwright'); const browser = await chromium.launch({ headless: true, ...(process.env.CHROME_PATH ? { executablePath: process.env.CHROME_PATH } : {}) }); const output = '.audit/background-frames'; const report = []; await mkdir(output, { recursive: true }); try { for (const theme of ['light', 'dark']) { const page = await browser.newPage({ viewport: { width: 1280, height: 820 } }); const errors = []; page.on('pageerror', error => errors.push(error.message)); await page.addInitScript(() => { window.isTauri = true; const root = 'C:/background-test'; const files = new Map([ ['welcome.md', '# Working notes\n\nKeep the image quiet behind readable text.\n\n## Next steps\n\n- Write a note\n- Review the code\n\n' + 'A paragraph with **bold text** and a [link](https://example.com).\n\n'.repeat(24)], ['hello.ts', '// A focused code view\nexport function greet(name: string) {\n const message = `Hello ${name}`;\n return message;\n}\n'], ]); window.__TAURI_INTERNALS__ = { metadata: { currentWindow: { label: 'main' }, currentWebview: { label: 'main' } }, transformCallback: () => 1, unregisterCallback() {}, invoke: async (command, args = {}) => { if (command === 'workspace_last_path') return root; if (command === 'workspace_open') return { root, name: 'background-test', watch_mode: 'native' }; if (command === 'workspace_list') return [...files.keys()].map(name => ({ name, rel_path: name, kind: 'file' })); if (command === 'workspace_read') { if (!files.has(args.rel)) throw new Error('missing'); return files.get(args.rel); } if (command === 'workspace_search') return []; if (command === 'plugins_snapshot') return { root, plugins: [] }; return null; }, }; window.__TAURI_EVENT_PLUGIN_INTERNALS__ = { unregisterListener() {} }; }); await page.goto(process.env.SMOKE_URL || 'http://127.0.0.1:1420'); await page.locator('.welcome-actions button').first().waitFor(); await page.getByText('background-test', { exact: true }).waitFor(); await page.evaluate(async theme => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); const { backgroundHub } = await import('/src/lib/plugins/backgrounds.ts'); const make = (first, second) => { const canvas = document.createElement('canvas'); canvas.width = 1200; canvas.height = 800; const ctx = canvas.getContext('2d'); const gradient = ctx.createLinearGradient(0, 0, 1200, 800); gradient.addColorStop(0, first); gradient.addColorStop(1, second); ctx.fillStyle = gradient; ctx.fillRect(0, 0, 1200, 800); ctx.strokeStyle = '#ffffff88'; ctx.lineWidth = 12; for (let x = 0; x < 1400; x += 200) { ctx.beginPath(); ctx.moveTo(x, 0); ctx.lineTo(x - 300, 800); ctx.stroke(); } return canvas.toDataURL(); }; const saved = make('#bd486c', '#438f67'); saveAppearance({ theme: 'default', mode: theme, newTabBackground: { image: saved, overlay: 0.15, position: 'center', size: 'cover' } }); const urls = await Promise.all([make('#bd486c', '#438f67'), make('#286f9b', '#725ea2')].map(async url => URL.createObjectURL(await (await fetch(url)).blob()))); window.backgroundTest = { hub: backgroundHub, owner: Symbol(), urls, saved, theme }; }, theme); const background = page.locator('.workarea-background'); assert.equal(await background.count(), 1); assert.equal(await page.locator('.empty h1, .empty > p').count(), 0); assert.equal(await page.locator('.empty').evaluate(node => getComputedStyle(node).backgroundImage), 'none'); const bounds = await background.boundingBox(); assert.equal(bounds.x, 0); assert.equal(bounds.y, 36); assert.equal(bounds.width, 1280); assert.equal(bounds.height, 762); assert.match(await background.evaluate(node => getComputedStyle(node).backgroundImage), /blob:/); assert.match(await page.locator('.left').evaluate(node => getComputedStyle(node).backgroundColor), /(?:0\.82|82%)/); assert.match(await page.locator('.right').evaluate(node => getComputedStyle(node).backgroundColor), /(?:0\.82|82%)/); assert.match(await page.locator('.welcome-actions button').first().evaluate(node => getComputedStyle(node).backgroundColor), /(?:0\.82|82%)/); assert.doesNotMatch(await page.locator('header.header').evaluate(node => getComputedStyle(node).backgroundColor), /(?:0\.82|82%)/); await page.locator('.welcome-actions button').first().focus(); await page.keyboard.press('Tab'); assert(await page.locator('.welcome-actions').evaluate(node => node.contains(document.activeElement))); await page.screenshot({ path: `${output}/${theme}-splash.png` }); await page.evaluate(() => { const { hub, owner, urls } = window.backgroundTest; hub.set(owner, 'app', { url: urls[0], blurredUrl: urls[1], overlay: 0.15, position: 'top', size: 'contain' }); }); assert.equal(await background.evaluate(node => getComputedStyle(node).backgroundSize), '100% 100%, contain, cover'); assert.equal(await background.evaluate(node => getComputedStyle(node).backgroundPosition), '50% 50%, 50% 0%, 50% 50%'); await page.screenshot({ path: `${output}/${theme}-portrait-layers.png` }); await page.setViewportSize({ width: 390, height: 700 }); assert.equal(await background.evaluate(node => getComputedStyle(node).backgroundSize), '100% 100%, contain, cover'); await page.screenshot({ path: `${output}/${theme}-portrait-layers-narrow.png` }); await page.setViewportSize({ width: 1280, height: 820 }); await page.evaluate(() => { const { hub, owner, urls } = window.backgroundTest; hub.set(owner, 'app', { url: urls[1], overlay: 0.2, position: 'center', size: 'cover', previous: { url: urls[0], overlay: 0.15, position: 'center', size: 'cover' }, transitionMs: 2000 }); }); await page.waitForTimeout(180); const opacity = await background.evaluate(node => Number(getComputedStyle(node, '::after').opacity)); assert(opacity > 0 && opacity < 1, `Fade has an intermediate opacity: ${opacity}`); await page.waitForTimeout(900); assert.ok(await background.evaluate(node => Number(getComputedStyle(node, '::after').opacity) < 1), 'The fade remains active after one second'); await page.waitForTimeout(1100); assert.equal(await background.evaluate(node => getComputedStyle(node, '::after').opacity), '1'); await page.keyboard.press('Control+p'); await page.getByRole('textbox', { name: 'Find a file' }).fill('welcome'); await page.getByRole('dialog').getByRole('button').filter({ hasText: 'welcome.md' }).first().click(); await page.getByRole('textbox', { name: 'Writing editor', exact: true }).waitFor(); assert.match(await page.locator('.editor > .body').evaluate(node => getComputedStyle(node).backgroundColor), /(?:0\.9|90%)/); await page.screenshot({ path: `${output}/${theme}-writer.png` }); await page.getByRole('group', { name: 'Document view', exact: true }).hover(); await page.getByRole('button', { name: 'Read', exact: true }).click(); await page.locator('.md-page').waitFor(); const beforeScroll = await background.boundingBox(); await page.locator('.md-page').evaluate(node => { node.scrollTop = 600; }); assert.deepEqual(await background.boundingBox(), beforeScroll); await page.screenshot({ path: `${output}/${theme}-reader.png` }); await page.getByRole('button', { name: 'Split', exact: true }).click(); await page.locator('.monaco-editor').waitFor(); assert.equal(await page.locator('.monaco-editor-background').first().evaluate(node => getComputedStyle(node).backgroundColor), 'rgba(0, 0, 0, 0)'); await page.screenshot({ path: `${output}/${theme}-split.png` }); await page.getByRole('button', { name: 'Edit', exact: true }).click(); await page.getByRole('group', { name: 'Editor layout', exact: true }).hover(); await page.getByRole('button', { name: 'IDE', exact: true }).click(); await page.locator('.monaco-editor').waitFor(); await page.screenshot({ path: `${output}/${theme}-ide.png` }); await page.setViewportSize({ width: 680, height: 720 }); await page.getByRole('button', { name: 'Files', exact: true }).click(); await page.getByRole('button', { name: 'Hide outline', exact: true }).click(); await page.screenshot({ path: `${output}/${theme}-ide-narrow.png` }); await page.keyboard.press('Control+t'); await page.locator('.welcome-actions').waitFor(); await page.setViewportSize({ width: 480, height: 640 }); assert(await page.locator('.empty').evaluate(node => node.scrollWidth <= node.clientWidth)); await page.screenshot({ path: `${output}/${theme}-splash-narrow.png` }); await page.emulateMedia({ reducedMotion: 'reduce' }); await page.evaluate(() => { const { hub, owner, urls } = window.backgroundTest; hub.set(owner, 'app', { url: urls[0], overlay: 0.2, position: 'center', size: 'cover', previous: { url: urls[1], overlay: 0.2, position: 'center', size: 'cover' }, transitionMs: 2000 }); }); assert.equal(await background.evaluate(node => node.getAnimations().length), 0); await page.evaluate(() => { const { hub, owner, urls } = window.backgroundTest; hub.removeOwner(owner); urls.forEach(URL.revokeObjectURL); }); assert.equal(await page.evaluate(() => document.body.style.getPropertyValue('--rs-background-previous-image')), ''); assert.match(await background.evaluate(node => getComputedStyle(node).backgroundImage), /blob:/); await page.evaluate(async () => { const { saveAppearance } = await import('/src/lib/theme/appearance.ts'); saveAppearance({ theme: 'default', mode: window.backgroundTest.theme }); }); assert.equal(await background.evaluate(node => getComputedStyle(node).backgroundImage), 'none'); await page.keyboard.press('Control+p'); await page.getByRole('textbox', { name: 'Find a file' }).fill('welcome'); await page.getByRole('dialog').getByRole('button').filter({ hasText: 'welcome.md' }).first().click(); await page.locator('.editor > .body').waitFor(); assert.equal(await page.locator('.editor > .body').evaluate(node => getComputedStyle(node).backgroundColor), await page.locator('.shell').evaluate(node => getComputedStyle(node).backgroundColor)); await page.screenshot({ path: output + '/' + theme + '-removed.png' }); assert.deepEqual(errors, []); report.push({ theme, passed: ['saved image', 'continuous workarea', 'sidebar transparency', 'button-only splash', 'keyboard focus', 'writer', 'reader scrolling', 'split', 'IDE transparency', 'narrow layout', 'fade', 'reduced motion', 'slideshow removal', 'saved image removal'], screenshots: `${output}/${theme}-*.png`, nativeDesktop: 'not tested' }); await page.close(); console.log(`PASS: ${theme} workarea backgrounds, editors, keyboard, narrow layout, fade, and restoration`); } await writeFile(`${output}/report.json`, JSON.stringify(report, null, 2)); } finally { await browser.close(); }