|
| 1 | +import { test, expect } from "@playwright/test"; |
| 2 | +import { readFile } from "node:fs/promises"; |
| 3 | +import { dirname, join } from "node:path"; |
| 4 | +import { fileURLToPath } from "node:url"; |
| 5 | + |
| 6 | +const __filename = fileURLToPath(import.meta.url); |
| 7 | +const __dirname = dirname(__filename); |
| 8 | + |
| 9 | +const ideVariants = [ |
| 10 | + { name: "vscode", background: "rgb(30, 30, 30)", foreground: "rgb(204, 204, 204)" }, |
| 11 | + { name: "intellij", background: "rgb(43, 43, 43)", foreground: "rgb(187, 187, 187)" }, |
| 12 | + { name: "visualStudio", background: "rgb(37, 37, 38)", foreground: "rgb(241, 241, 241)" }, |
| 13 | + { name: "eclipse", background: "rgb(27, 30, 35)", foreground: "rgb(216, 221, 229)" }, |
| 14 | +]; |
| 15 | + |
| 16 | +const panels = [ |
| 17 | + { name: "tree-view", fixture: "tree-view.html" }, |
| 18 | + { name: "config-page", fixture: "config-page.html" }, |
| 19 | + { name: "code-suggestion", fixture: "code-suggestion.html" }, |
| 20 | + { name: "oss-suggestion", fixture: "oss-suggestion.html" }, |
| 21 | + { name: "iac-suggestion", fixture: "iac-suggestion.html" }, |
| 22 | + { name: "secrets-suggestion", fixture: "secrets-suggestion.html" }, |
| 23 | + { name: "scan-summary", fixture: "scan-summary.html" }, |
| 24 | +]; |
| 25 | + |
| 26 | +for (const panel of panels) { |
| 27 | + for (const ide of ideVariants) { |
| 28 | + test(`screenshot: ${panel.name} × ${ide.name}`, async ({ page }, testInfo) => { |
| 29 | + const rawHtml = await readFile(join(__dirname, "fixtures", panel.fixture), "utf8"); |
| 30 | + // Strip CSP meta tags — fixtures contain webview CSPs that block test-injected styles. |
| 31 | + const html = rawHtml.replace(/<meta[^>]*http-equiv=["']Content-Security-Policy["'][^>]*>/gi, ""); |
| 32 | + await page.setViewportSize({ width: 1280, height: 900 }); |
| 33 | + await page.setContent(html, { waitUntil: "domcontentloaded" }); |
| 34 | + await page.addStyleTag({ |
| 35 | + content: `body { background-color: ${ide.background} !important; color: ${ide.foreground} !important; }`, |
| 36 | + }); |
| 37 | + const buf = await page.screenshot({ fullPage: true, animations: "disabled" }); |
| 38 | + await testInfo.attach(`${panel.name}-${ide.name} (full page)`, { |
| 39 | + body: buf, |
| 40 | + contentType: "image/png", |
| 41 | + }); |
| 42 | + await expect(page).toHaveScreenshot(`${panel.name}-${ide.name}.png`, { |
| 43 | + fullPage: true, |
| 44 | + threshold: 0.2, |
| 45 | + maxDiffPixelRatio: 0.02, |
| 46 | + animations: "disabled", |
| 47 | + }); |
| 48 | + }); |
| 49 | + } |
| 50 | +} |
0 commit comments