

























@@ -70,7 +70,7 @@ async function expectRemoteMediaMaxBytesError(params: {
7070async function expectRedactedBotTokenFetchError(params: {
7171botFileUrl: string;
7272botToken: string;
73-redactedBotToken: string;
73+expectedErrorText: string;
7474fetchImpl: Parameters<typeof fetchRemoteMedia>[0]["fetchImpl"];
7575}) {
7676const error = await fetchRemoteMedia({
@@ -87,7 +87,7 @@ async function expectRedactedBotTokenFetchError(params: {
8787expect(error).toBeInstanceOf(Error);
8888const errorText = error instanceof Error ? String(error) : "";
8989expect(errorText).not.toContain(params.botToken);
90-expect(errorText).toContain(`bot${params.redactedBotToken}`);
90+expect(errorText).toBe(params.expectedErrorText);
9191}
92929393async function expectFetchRemoteMediaRejected(params: {
@@ -266,16 +266,18 @@ describe("fetchRemoteMedia", () => {
266266fetchImpl: vi.fn(async () => {
267267throw new Error(`dial failed for ${botFileUrl}`);
268268}),
269+expectedErrorText: `MediaFetchError: Failed to fetch media from https://files.example.test/file/bot${redactedBotToken}/photos/1.jpg: dial failed for https://files.example.test/file/bot${redactedBotToken}/photos/1.jpg`,
269270},
270271{
271272name: "redacts bot tokens from HTTP error messages",
272273fetchImpl: vi.fn(async () => new Response("unauthorized", { status: 401 })),
274+expectedErrorText: `MediaFetchError: Failed to fetch media from https://files.example.test/file/bot${redactedBotToken}/photos/1.jpg: HTTP 401; body: unauthorized`,
273275},
274-] as const)("$name", async ({ fetchImpl }) => {
276+] as const)("$name", async ({ fetchImpl, expectedErrorText }) => {
275277await expectRedactedBotTokenFetchError({
276278 botFileUrl,
277279 botToken,
278-redactedBotToken,
280+expectedErrorText,
279281 fetchImpl,
280282});
281283});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。