fix: mock github checks in tests

This commit is contained in:
Frostebite
2025-08-02 19:38:47 +01:00
parent 9e91ca9749
commit 44586b3388
2 changed files with 38 additions and 0 deletions

View File

@@ -1,5 +1,24 @@
import failOnConsole from 'jest-fail-on-console';
// Polyfill fetch for the Node.js test environment.
// Jest runs tests inside a VM context where the global `fetch` is not
// automatically provided, even on Node 18+. Octokit requires a `fetch`
// implementation, so we provide one using undici's implementation.
// This ensures tests that interact with Octokit do not throw when
// constructing the client.
import { fetch, Headers, Request, Response } from 'undici';
if (!global.fetch) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(global as any).fetch = fetch;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(global as any).Headers = Headers;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(global as any).Request = Request;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(global as any).Response = Response;
}
// Fail when console logs something inside a test - use spyOn instead
failOnConsole({
shouldFailOnWarn: true,