mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-08-02 09:02:15 +03:00
Improve frontend test framework (#22824)
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
CI / AMD64 Build (push) Waiting to run
CI / ARM Build (push) Waiting to run
CI / Jetson Jetpack 6 (push) Waiting to run
CI / AMD64 Extra Build (push) Blocked by required conditions
CI / ARM Extra Build (push) Blocked by required conditions
CI / Synaptics Build (push) Blocked by required conditions
CI / Assemble and push default build (push) Blocked by required conditions
CI / AMD64 Build (push) Waiting to run
* add error allowlist file for error collector * add error collector for console + page + request errors * wire error collector into frigateApp fixture * add self-tests for error collector fixture * gate strict error mode on E2E_STRICT_ERRORS=1 * triage pre-existing errors and seed allowlist * add mockEmpty/mockError/mockDelay helpers for state-driven tests * add self-tests for mock override helpers * add mobile affordance helpers to BasePage * add lint script for banned spec patterns and @mobile rule * apply prettier fixes to new e2e files * rewrite export.spec.ts * clean up * move export spec rewrite and bugfix to separate branch
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Per-test mock overrides for driving empty / loading / error states.
|
||||
*
|
||||
* Playwright route handlers are LIFO: the most recently registered handler
|
||||
* matching a URL takes precedence. The frigateApp fixture installs default
|
||||
* mocks before the test body runs, so these helpers — called inside the
|
||||
* test body — register AFTER the defaults and therefore win.
|
||||
*
|
||||
* Always call these BEFORE the navigation that triggers the request.
|
||||
*
|
||||
* Example:
|
||||
* await mockEmpty(page, "**\/api\/exports**");
|
||||
* await frigateApp.goto("/export");
|
||||
* // Page now renders the empty state
|
||||
*/
|
||||
|
||||
import type { Page } from "@playwright/test";
|
||||
|
||||
/** Return an empty array for the matched endpoint. */
|
||||
export async function mockEmpty(
|
||||
page: Page,
|
||||
urlPattern: string | RegExp,
|
||||
): Promise<void> {
|
||||
await page.route(urlPattern, (route) => route.fulfill({ json: [] }));
|
||||
}
|
||||
|
||||
/** Return an HTTP error for the matched endpoint. Default status 500. */
|
||||
export async function mockError(
|
||||
page: Page,
|
||||
urlPattern: string | RegExp,
|
||||
status = 500,
|
||||
): Promise<void> {
|
||||
await page.route(urlPattern, (route) =>
|
||||
route.fulfill({
|
||||
status,
|
||||
json: { success: false, message: "Mocked error" },
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delay the response by `ms` milliseconds before fulfilling with the
|
||||
* provided body. Use to assert loading-state UI is visible during the
|
||||
* delay window.
|
||||
*/
|
||||
export async function mockDelay(
|
||||
page: Page,
|
||||
urlPattern: string | RegExp,
|
||||
ms: number,
|
||||
body: unknown = [],
|
||||
): Promise<void> {
|
||||
await page.route(urlPattern, async (route) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, ms));
|
||||
await route.fulfill({ json: body });
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user