Skip to content
Source
Sign inSign up
pingdotgg/t3code

test: warn on polling loops in tests and make adapter test harnesses event-driven #22565

Mergedjuliusmarmingemerged 4 commits intotests/no-real-time-wait fromtests/no-polling-loopmerged by juliusmarminge View on GitHub

Showing 8 changed files with 73 additions and 26 deletions (loading 7).

x
0 of 8 viewed, 8 left
73 additions and 26 deletionsapps/desktop/src/preview/Manager.test.tsModified
View file
@@ -376,6 +376,7 @@
​
const makeFaviconWebContents = (options?: {
+ readonly changes?: ChangeSignal;
readonly fetch?: (url: string, init?: RequestInit) => Promise<Response>;
readonly id?: number;
readonly rasterize?: (code: string) => Promise<unknown>;
@@ -386,16 +387,25 @@
let currentUrl = options?.url ?? "http://localhost:3200/";
let destroyed = false;
let loading = false;
- const fetch = vi.fn(
+ const fetchImpl =
options?.fetch ??
- (async () =>
- new Response(new Uint8Array(sourcePng), {
- headers: { "content-type": "image/png" },
- })),
- );
+ (async () =>
+ new Response(new Uint8Array(sourcePng), {
+ headers: { "content-type": "image/png" },
+ }));
+ const fetch = vi.fn((url: string, init?: RequestInit) => {
+ const response = fetchImpl(url, init);
+ options?.changes?.notify();
+ return response;
+ });