// iwb-dev-probe: 设计 token 视觉基线(M0/T0.2),不入常规门禁(下划线前缀 + 此标记 = 被 scripts/list-e2e-specs.js 排除) // // 为什么不做成门禁 spec: // ① 截图像素受**字体渲染**(系统是否装同版本中文字体)、**DPR**、**GPU 合成**影响, // 跨机器必然漂移 → 挂门禁就是把机器差异变成 CI 红灯; // ② 它的用途是「我改完这一批,和上一批比 0 diff」,属于本地验收工具,不是代码正确性断言。 // // 用法: // npm run build && node scripts/serve-test.js & # 端口 8787 // npx playwright test _visual-tokens --update-snapshots # 首次生成/确认变更 // npx playwright test _visual-tokens # 比对(0 diff 才算过) // // 8 个场景 × 亮/暗 = 16 张,覆盖「壳层 / 画布 / 浮层 / 抽屉 / 插件面板 / 右键菜单 / // 插件管理 / 插件市场」八类界面。⑦⑧ 是 M6 重做插件面板时补的:那一整段样式此前**没有基线**, // 六次叠加的改动全靠人眼看,等于最乱的地方最没保护。 // 稳定化:固定 1280×800 + deviceScaleFactor 1、animations disabled、caret hide、等字体与两帧。 const { test, expect } = require('./_pw-coverage') const baseURL = process.env.IWB_BASE_URL || 'http://127.0.0.1:8787' test.use({ baseURL, viewport: { width: 1280, height: 800 }, deviceScaleFactor: 1 }) // 预置一张「有东西可看」且**在视口内**的画布:提示词 → 文本 / 组合,组合 → 配置。 // 不放 out 节点:它的节点体是一张大卡片,会把画布基线变成「一张图 vs 一堆节点」的对比。 const WS = { workspaces: [{ id: 'ws_visual', name: '视觉基线', groups: [], nodes: [ { id: 'p1', type: 'prompt', x: 240, y: 180, data: { text: '一只橘猫坐在窗台上,午后阳光,胶片质感' } }, { id: 't1', type: 'textout', x: 600, y: 180, data: {} }, { id: 'c1', type: 'combine', x: 240, y: 400, data: {} }, { id: 'g1', type: 'gen', x: 600, y: 400, data: { size: '1024x1024', n: 1 } }, ], edges: [ { id: 'e1', from: 'p1', to: 't1' }, { id: 'e2', from: 'p1', to: 'c1' }, { id: 'e3', from: 'c1', to: 'g1' }, ], }], activeId: 'ws_visual', rev: 1, schemaVersion: 1, } const CFG = { providers: [], canvas: {} } // 停靠栏状态:左栏停在「节点组」(默认「浏览器」面板在网页环境下只有一句客户端提示, // 「风格库」首帧是异步加载态,两者都不适合做像素基线);右栏默认关,④⑤ 用例自己点开。 const DOCK = { left: { open: true, w: 318, list: ['groups', 'browser', 'styles'], removed: [], active: 'groups' }, right: { open: false, w: 330, list: ['prompts', 'gallery'], removed: [], active: 'gallery' }, } // 主题走 iwb_theme(app.js initTheme 的读取键);清掉外观覆盖,保证基线是「出厂派生色」 async function seed(page, theme) { await page.addInitScript(({ cfg, ws, dock, theme }) => { localStorage.clear() localStorage.setItem('iwb_web_cfg', JSON.stringify(cfg)) localStorage.setItem('iwb_web_workspaces', JSON.stringify(ws)) localStorage.setItem('iwb_ws_active', ws.activeId) localStorage.setItem('iwb_theme', theme) localStorage.setItem('iwb.dock.v1', JSON.stringify(dock)) }, { cfg: CFG, ws: WS, dock: DOCK, theme }) } // 等「真的画完了」:字体就绪 + 连续两帧 + 没有正在跑的动画帧(rAF 计数稳定) async function settle(page) { await page.evaluate(() => document.fonts && document.fonts.ready) await page.evaluate(() => new Promise((resolve) => { let left = 3 const step = () => { left -= 1; if (left <= 0) resolve(); else requestAnimationFrame(step) } requestAnimationFrame(step) })) await page.waitForTimeout(250) // 少量固定等待:等 CSS 过渡(120ms)收尾;本文件不进门禁,不影响固定等待棘轮 } async function shot(page, name) { await settle(page) await expect(page).toHaveScreenshot(name + '.png', { animations: 'disabled', caret: 'hide', maxDiffPixels: 0, // threshold 默认 0.2(每像素 YCbCr 距离),`maxDiffPixels: 0` 只是「超阈值的像素数为 0」—— // 两者叠加并不等于逐像素精确。B5 踩到:端口描边色改了约 19 级,全被 0.2 吃掉, // 基线没更新、比对还显示 12/12 通过(假绿灯)。这里显式压到 0,让「0 diff」名副其实。 threshold: 0, }) } async function bootHome(page, theme) { await seed(page, theme) await page.goto('/', { waitUntil: 'domcontentloaded' }) await page.waitForSelector('.iwb-home-card:not(.iwb-home-new)', { timeout: 20000 }) await settle(page) } async function bootCanvas(page, theme) { await bootHome(page, theme) await page.locator('.iwb-home-card:not(.iwb-home-new)').first().dblclick() await page.waitForSelector('.iwb-canvas:not(.iwb-canvas-hidden)', { timeout: 20000 }) await expect(page.locator('.iwb-node')).toHaveCount(4, { timeout: 15000 }) // 画布基线关掉左栏:打开时它浮在画布之上 318px,而首次进入的自动取景只按窗口宽度居中 // (不避让停靠栏),节点必然被压一半。停靠栏本身由 ④⑤ 两张右栏截图覆盖。 const toggle = page.locator('.iwb-top-nav-icon[title="显示 / 隐藏左栏"]').first() await toggle.click() await expect(page.locator('.iwb-dock[data-side="left"]')).toHaveCount(0) await page.waitForTimeout(300) } // 右栏默认是关的(dock 状态 right.open=false),必须点顶栏开关;开完等面板挂载 async function openRightDock(page) { await page.locator('.iwb-top-nav-icon[title="显示 / 隐藏右栏"]').first().click() await expect(page.locator('.iwb-dock[data-side="right"]')).toBeVisible({ timeout: 15000 }) await page.waitForTimeout(400) // 插件面板挂载是异步的(pluginMount effect) } // ── ⑦⑧ 组件夹具 ──────────────────────────────────────────────────────── // 为什么不用整页截图:插件管理/市场这一屏由 DesktopPluginsTab 渲染,而它在 // `isDesk()` 为 false 时(网页 e2e 环境)走的是另一条分支(.iwb-plugin-row 清单), // 这条最乱的样式反而截不到。夹具用同一套类名 + 真实 dist/style.css 渲染, // 覆盖「设置行 / 列表行 / 开关 / 工具条 / 筛选胶囊 / 卡片」六种形态。 const PANEL_HTML = `