chore(frontend): tighten eslint/axe gates, remove reader waivers (B5 done, spec ② complete)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { expect, test, type APIRequestContext } from "@playwright/test";
|
||||
import { adminApi, creds, ensureSampleBook } from "./helpers/api";
|
||||
import { adminApiRetry, creds, ensureSampleBook } from "./helpers/api";
|
||||
import { scanA11y } from "./helpers/axe";
|
||||
|
||||
let admin: APIRequestContext;
|
||||
@@ -7,7 +7,7 @@ let bookId: number;
|
||||
let title: string;
|
||||
|
||||
test.beforeAll(async () => {
|
||||
admin = await adminApi();
|
||||
admin = await adminApiRetry();
|
||||
bookId = await ensureSampleBook(admin, "e2e");
|
||||
// 标题以 API 实况为准:后端 titleOf 可能改写文件名(下划线→空格等),书架卡按真实标题找。
|
||||
title = ((await (await admin.get(`/api/books/${bookId}`)).json()) as { title: string }).title;
|
||||
|
||||
@@ -31,6 +31,18 @@ export async function adminApi(): Promise<APIRequestContext> {
|
||||
return request.newContext({ baseURL: BASE, extraHTTPHeaders: { Authorization: `Bearer ${token}` } });
|
||||
}
|
||||
|
||||
/** adminApi 登录带 429 退避重试:三 spec 并发 worker 的登录总数可能顶到后端 1min/5 次限流门,等窗口即可;仅消耗等待预算,不改用例语义 */
|
||||
export async function adminApiRetry(): Promise<APIRequestContext> {
|
||||
for (let i = 0; ; i++) {
|
||||
try {
|
||||
return await adminApi();
|
||||
} catch (e) {
|
||||
if (i > 20 || !(e instanceof Error) || !e.message.includes("HTTP 429")) throw e;
|
||||
await new Promise((r) => setTimeout(r, 3000));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function ensureLibrary(ctx: APIRequestContext, name: string): Promise<number> {
|
||||
const libs = (await (await ctx.get("/api/libraries")).json()) as { id: number; name: string }[];
|
||||
const hit = libs.find((l) => l.name === name);
|
||||
|
||||
@@ -8,18 +8,10 @@ interface Waiver {
|
||||
}
|
||||
|
||||
/**
|
||||
* critical/serious 违规的逐条豁免清单(spec S3):
|
||||
* 仅允许「属于将被 ② 阅读器改版重写的旧 chrome」的问题进这里,reason 必须写明归属。
|
||||
* 例:{ page: "reader-chrome", rule: "color-contrast", reason: "旧 rd-* chrome 配色,② 迁移 shadcn token 后移除本豁免" }
|
||||
* critical/serious 违规的逐条豁免清单(④ 基建):
|
||||
* ② 阅读器改版后旧 chrome 重写完毕,本期清空;新增豁免必须写明 reason 并控制在一次性条件。
|
||||
*/
|
||||
const WAIVERS: Waiver[] = [
|
||||
{
|
||||
page: "reader-chrome",
|
||||
rule: "color-contrast",
|
||||
reason:
|
||||
"旧 chrome:Reader.tsx 头栏(书架返回钮/书名/库名/进度)用 stone-* 配色,对比不足;② 阅读器改版迁移 shadcn token 后移除本豁免",
|
||||
},
|
||||
];
|
||||
const WAIVERS: Waiver[] = [];
|
||||
|
||||
export async function scanA11y(page: Page, name: string): Promise<void> {
|
||||
// 等 CSS 动画/过渡收尾(如 fx-rise 入场淡入)再扫:动画途中采样会因不透明度混色造成 contrast 误报;2s 上限兜底长动画
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { expect, test, type APIRequestContext } from "@playwright/test";
|
||||
import { adminApi, creds, ensureBook, FIXTURE_TXT } from "./helpers/api";
|
||||
import { adminApiRetry, creds, ensureBook, FIXTURE_TXT } from "./helpers/api";
|
||||
import { scanA11y } from "./helpers/axe";
|
||||
|
||||
let admin: APIRequestContext;
|
||||
let bookId: number;
|
||||
|
||||
test.beforeAll(async () => {
|
||||
admin = await adminApi();
|
||||
admin = await adminApiRetry();
|
||||
// 文件名避免与 CBZ 样本书同名:fixture 用 e2e-sample-txt.txt(title=e2e-sample-txt)
|
||||
bookId = await ensureBook(admin, "e2e", "e2e-sample-txt.txt", FIXTURE_TXT);
|
||||
});
|
||||
@@ -46,6 +46,17 @@ test("登录 → txt 阅读 → 全书搜索 → 跳转", async ({ page }) => {
|
||||
|
||||
await scanA11y(page, "reader-chrome");
|
||||
|
||||
// 设置面板冒烟:字号/行距即时生效 + 主题卡联动阅读面(data-rd 受控)
|
||||
const pre = page.locator(".rd-surface pre");
|
||||
await expect(pre).toHaveCSS("font-size", "20px");
|
||||
await page.getByRole("button", { name: "更多阅读设置" }).click();
|
||||
await page.getByRole("button", { name: "加大字号" }).click();
|
||||
await expect(pre).toHaveCSS("font-size", "22px");
|
||||
await page.getByRole("button", { name: "1.8", exact: true }).click();
|
||||
await expect(pre).toHaveAttribute("style", /line-height: 1\.8/);
|
||||
await page.getByRole("button", { name: "夜色主题" }).click();
|
||||
await expect(page.locator(".rd-surface").first()).toHaveAttribute("data-rd", "night");
|
||||
|
||||
// 退出
|
||||
await page.getByRole("link", { name: "书架" }).click();
|
||||
await expect(page).toHaveURL(/\/$/);
|
||||
|
||||
Reference in New Issue
Block a user