문제: 라우트 로딩 화면(280 px)은 720 px 창에 들고 홈 화면(732 px 문서)은
넘친다. 일반(overlay가 아닌) 스크롤바를 쓰는 브라우저에서 홈이 그려지는
프레임에 세로 스크롤바가 생겨 너비가 15 px 줄고 header 오른쪽(세션 영역)이
15 px 밀린다(1280x720·1366x657에서 CLS 0.0002, 리뷰 15-R2 12회). lab과 모든
게이트의 Playwright Chromium은 --hide-scrollbars로 떠서 이 shift를 못 본다.
고른 방법:
- base.css의 :root에 scrollbar-gutter: stable을 둔다. 스크롤바 자리가
첫 프레임부터 있어 내용이 길어져도 너비가 바뀌지 않는다. overlay
스크롤바(macOS 기본)는 어느 쪽이든 자리를 쓰지 않는다.
- lab(scripts/test-performance.ts)은 labBrowserLaunchOptions()로
--hide-scrollbars를 빼고 띄운다. lab.json context.browser에
scrollbars: "visible"을 남긴다. 이제 lab의 `/` CLS가 같은 회귀를 본다.
- 단위 테스트: 실행 옵션이 --hide-scrollbars를 빼는지, :root에
scrollbar-gutter: stable이 있는지.
- 시각 골든 5장을 새 gutter에 맞춰 desktop에서 다시 찍는다
(test:visual:update).
버린 대안: html { overflow-y: scroll } — 짧은 화면에도 빈 스크롤바를
그린다.
위험·한계: 스크롤바 폭만큼 오른쪽 여백이 짧은 화면에서도 늘 생긴다.
--hide-scrollbars로 뜬 Chromium도 gutter 자리를 잡는다. 그래서 시각 골든
5장이 모두 바뀌었다. 바뀐 것은 내용 폭 15 px다(main 1040 → 1025 px).
compact(390 px) 골든은 줄바꿈이 늘어 1297 → 1377 px로 길어졌다. 실제
휴대폰은 overlay 스크롤바라 자리를 쓰지 않으므로, compact 골든은 휴대폰
화면보다 15 px 좁게 그린다. 열린 drawer의 가림막은 gutter를 덮지 않는다
(일반 스크롤바 브라우저에서는 그 자리에 스크롤바가 그려진다). lab의 CLS 예산
0.1은 그대로라 0.0002 shift가 다시 생겨도 lab은 통과한다(값만 남는다).
Firefox·Windows 스크롤바 폭은 재지 않았다.
검증: desktop batch에서 확인.
node scripts/run-vitest.ts run tests/unit/lab-performance.test.ts
corepack pnpm test:visual (부모 d5b6aeba에서 6건 통과, 이 변경은 옛
골든과 5건이 달라 실패, 다시 찍은 골든에서 통과)
corepack pnpm build && corepack pnpm test:performance -- --runs=5
Refs: 1105/15-05
129 lines
4.4 KiB
TypeScript
129 lines
4.4 KiB
TypeScript
import { spawn } from "node:child_process";
|
|
import { readFile } from "node:fs/promises";
|
|
import { createServer, type Server } from "node:http";
|
|
import type { AddressInfo } from "node:net";
|
|
import path from "node:path";
|
|
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
assertPortUnused,
|
|
assertServedRelease,
|
|
labBrowserLaunchOptions,
|
|
previewArguments,
|
|
summarizeSamples,
|
|
} from "../../scripts/lib/lab-performance.ts";
|
|
|
|
/**
|
|
* 11-07. The lab performance gate measured once, and measured whatever server
|
|
* held its port: `vite preview` without `--strictPort` moved elsewhere and the
|
|
* script never checked which build answered.
|
|
*/
|
|
const servers: Server[] = [];
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(
|
|
servers.splice(0).map(
|
|
(server) => new Promise<void>((resolve) => server.close(() => resolve())),
|
|
),
|
|
);
|
|
});
|
|
|
|
async function foreignServer(manifest: unknown): Promise<string> {
|
|
const server = createServer((_request, response) => {
|
|
response
|
|
.writeHead(200, { "content-type": "application/json" })
|
|
.end(JSON.stringify(manifest));
|
|
});
|
|
servers.push(server);
|
|
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", () => resolve()));
|
|
return `http://127.0.0.1:${(server.address() as AddressInfo).port}`;
|
|
}
|
|
|
|
describe("lab performance gate (11-07)", () => {
|
|
it("starts the preview server on exactly the requested port", () => {
|
|
expect(previewArguments(4173)).toEqual([
|
|
"pnpm",
|
|
"preview",
|
|
"--host",
|
|
"127.0.0.1",
|
|
"--port",
|
|
"4173",
|
|
"--strictPort",
|
|
]);
|
|
});
|
|
|
|
it("summarizes repeated runs by their median and keeps every sample", () => {
|
|
expect(summarizeSamples([326, 1103, 410, 390, 505])).toEqual({
|
|
median: 410,
|
|
min: 326,
|
|
max: 1103,
|
|
samples: [326, 1103, 410, 390, 505],
|
|
});
|
|
expect(summarizeSamples([1, 4, 2, 3]).median).toBe(2.5);
|
|
expect(() => summarizeSamples([])).toThrow(RangeError);
|
|
});
|
|
|
|
it("refuses a port that another server already answers on", async () => {
|
|
const baseUrl = await foreignServer({});
|
|
await expect(assertPortUnused(baseUrl)).rejects.toThrow(/another server/u);
|
|
await expect(assertPortUnused("http://127.0.0.1:9")).resolves.toBeUndefined();
|
|
});
|
|
|
|
it("refuses a server that serves a different build", async () => {
|
|
const baseUrl = await foreignServer({ buildId: "other", releaseId: "r1" });
|
|
await expect(
|
|
assertServedRelease(baseUrl, { buildId: "measured", releaseId: "r1" }),
|
|
).rejects.toThrow(/serves build other\/r1, not the measured measured\/r1/u);
|
|
await expect(
|
|
assertServedRelease(baseUrl, { buildId: "other", releaseId: "r1" }),
|
|
).resolves.toBeUndefined();
|
|
});
|
|
|
|
it("fails the gate before measuring when its port is taken", async () => {
|
|
const baseUrl = await foreignServer({ buildId: "other", releaseId: "r1" });
|
|
const child = spawn(
|
|
process.execPath,
|
|
[path.resolve("scripts/test-performance.ts")],
|
|
{
|
|
env: { ...process.env, LAB_PERFORMANCE_PORT: new URL(baseUrl).port },
|
|
stdio: ["ignore", "ignore", "pipe"],
|
|
},
|
|
);
|
|
let stderr = "";
|
|
child.stderr.on("data", (chunk: Buffer) => {
|
|
stderr += chunk.toString("utf8");
|
|
});
|
|
const code = await new Promise<number | null>((resolve) => {
|
|
const timer = setTimeout(() => child.kill("SIGKILL"), 20_000);
|
|
child.on("exit", (exitCode) => {
|
|
clearTimeout(timer);
|
|
resolve(exitCode);
|
|
});
|
|
});
|
|
|
|
expect(code).not.toBe(0);
|
|
expect(stderr).toMatch(/another server holds the port/u);
|
|
}, 30_000);
|
|
});
|
|
|
|
/**
|
|
* 1105/15-05. The home page's first render added a vertical scrollbar and
|
|
* pushed the header's right side 15 px (CLS 0.0002 at 1280x720 and
|
|
* 1366x657). Every gate's Chromium hid scrollbars, the lab included, so no
|
|
* gate could see it. The page reserves the gutter, and the lab measures with
|
|
* the scrollbar a Windows or Linux desktop draws.
|
|
*/
|
|
describe("lab performance with real scrollbars (1105/15-05)", () => {
|
|
it("starts Chromium without Playwright's --hide-scrollbars", () => {
|
|
expect(labBrowserLaunchOptions().ignoreDefaultArgs).toContain("--hide-scrollbars");
|
|
});
|
|
|
|
it("reserves the root scrollbar gutter before the first route renders", async () => {
|
|
const base = await readFile("src/presentation/styles/theme/base.css", "utf8");
|
|
const root = base.match(/:root\s*\{([^}]*)\}/u)?.[1] ?? "";
|
|
|
|
expect(root).toMatch(/scrollbar-gutter:\s*stable\s*;/u);
|
|
});
|
|
});
|