- Move external URL checks to its own module under `tests/`. This separates them from integration test, addressing long runs and frequent failures that led to ignoring test results. - Move `check-desktop-runtime-errors` to `tests/checks` to keep all test-related checks into one directory. - Replace `ts-node` with `vite` for running `check-desktop-runtime-errors` to maintain a consistent execution environment across checks. - Implement a timeout for each fetch call. - Be nice to external sources, wait 5 seconds before sending another request to an URL under same domain. This solves rate-limiting issues. - Instead of running test on every push/pull request, run them only weekly. - Do not run tests on each commit/PR but only scheduled (weekly) to minimize noise. - Fix URLs are not captured correctly inside backticks or parenthesis.
17 lines
456 B
TypeScript
17 lines
456 B
TypeScript
import fetch from 'cross-fetch';
|
|
|
|
export async function fetchWithTimeout(
|
|
url: string,
|
|
timeoutInMs: number,
|
|
init?: RequestInit,
|
|
): Promise<Response> {
|
|
const controller = new AbortController();
|
|
const options: RequestInit = {
|
|
...(init ?? {}),
|
|
signal: controller.signal,
|
|
};
|
|
const promise = fetch(url, options);
|
|
const timeout = setTimeout(() => controller.abort(), timeoutInMs);
|
|
return promise.finally(() => clearTimeout(timeout));
|
|
}
|