fix: mock github checks in tests
parent
9e91ca9749
commit
44586b3388
|
@ -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,
|
||||
|
|
|
@ -17,6 +17,25 @@ describe('Cloud Runner Github Checks', () => {
|
|||
it('Responds', () => {});
|
||||
|
||||
if (CloudRunnerOptions.cloudRunnerDebug) {
|
||||
beforeEach(() => {
|
||||
// Mock GitHub API requests to avoid real network calls
|
||||
jest.spyOn(GitHub as any, 'createGitHubCheckRequest').mockResolvedValue({
|
||||
status: 201,
|
||||
data: { id: '1' },
|
||||
});
|
||||
jest.spyOn(GitHub as any, 'updateGitHubCheckRequest').mockResolvedValue({
|
||||
status: 200,
|
||||
data: {},
|
||||
});
|
||||
jest
|
||||
.spyOn(GitHub as any, 'runUpdateAsyncChecksWorkflow')
|
||||
.mockResolvedValue(undefined);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
it(
|
||||
'Check Handling Direct',
|
||||
async () => {
|
||||
|
|
Loading…
Reference in New Issue