diff --git a/packages/cli/src/commands/validate.media-fit.test.ts b/packages/cli/src/commands/validate.media-fit.test.ts index 66a248cb60..186595064e 100644 --- a/packages/cli/src/commands/validate.media-fit.test.ts +++ b/packages/cli/src/commands/validate.media-fit.test.ts @@ -99,4 +99,30 @@ describe("audio the page never loaded", () => { expect.stringContaining('Audio "voice" is 3.00s'), ]); }); + + it("says a source that failed to load is not a timeout", async () => { + class MissingProbe extends EventTarget { + preload = ""; + duration = Number.NaN; + error: { code: number } | null = null; + set src(_url: string) { + queueMicrotask(() => { + this.error = { code: 4 }; + this.dispatchEvent(new Event("error")); + }); + } + } + vi.stubGlobal("Audio", MissingProbe); + document.body.innerHTML = ''; + const evaluate: Page["evaluate"] = async (fn, ...args) => { + if (typeof fn !== "function") throw new Error("Expected a browser function"); + return window.eval(`(${fn.toString()})`)(...args); + }; + + const warnings = await auditClipDurations({ evaluate }, analyzeClipMediaFit, 1000); + + expect(warnings).toHaveLength(1); + expect(warnings[0]?.text).toContain("failed to load (voice)"); + expect(warnings[0]?.text).not.toContain("Re-run with a longer --timeout"); + }); }); diff --git a/packages/cli/src/commands/validate.ts b/packages/cli/src/commands/validate.ts index f86e9b04a7..1b76f70e56 100644 --- a/packages/cli/src/commands/validate.ts +++ b/packages/cli/src/commands/validate.ts @@ -140,6 +140,29 @@ export function raceMediaReady( }); } +function unmeasuredClipWarnings(unreadable: string[], unloadable: string[]): ConsoleEntry[] { + const warnings: ConsoleEntry[] = []; + if (unreadable.length > 0) { + warnings.push({ + level: "warning", + text: + `Could not read the duration of ${unreadable.length} media element(s) within the ` + + `validate timeout (${unreadable.join(", ")}); their slot vs. source fit was not checked. ` + + `Re-run with a longer --timeout if the source is slow to load.`, + }); + } + if (unloadable.length > 0) { + warnings.push({ + level: "warning", + text: + `${unloadable.length} media element(s) failed to load (${unloadable.join(", ")}), so ` + + `their slot vs. source fit was not checked. A longer --timeout will not help: check ` + + `that the source exists and plays in Chrome.`, + }); + } + return warnings; +} + /** * Flag `