更新说明文档
大石头 authored at 2022-04-16 15:30:05
1.13 KiB
YuQue
import { test } from '@playwright/test';
import fs from 'node:fs';
import { dirname } from 'node:path';
import { fileURLToPath, pathToFileURL } from 'node:url';

/**
 * 阶段 D 辅助:把 Doc/Design 静态设计稿渲染为截图基线
 * 运行:npx playwright test tests/baseline.spec.ts --project=desktop
 */
const DESIGNS = [
  ['home', 'home.html'],
  ['list', 'list.html'],
  ['info', 'info.html'],
  ['search', 'search.html'],
  ['product', 'product.html'],
];
const REPO = fileURLToPath(new URL('../..', import.meta.url)); // E2ETest 上一级即仓库根
const OUT = fileURLToPath(new URL('../.artifacts/baseline/', import.meta.url));

test.describe('设计稿基线', () => {
  for (const [name, file] of DESIGNS) {
    test(`渲染 ${name}`, async ({ page }) => {
      fs.mkdirSync(dirname(`${OUT}${name}.png`), { recursive: true });
      const url = pathToFileURL(`${REPO}Doc/Design/${file}`).href;
      await page.setViewportSize({ width: 1280, height: 900 });
      await page.goto(url, { waitUntil: 'load' });
      await page.waitForTimeout(600);
      await page.screenshot({ path: `${OUT}${name}.png`, fullPage: true });
    });
  }
});