mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-10-07 13:58:33 +08:00
* deps(deps-dev): bump typescript from 5.9.3 to 6.0.3 Bumps [typescript](https://github.com/microsoft/TypeScript) from 5.9.3 to 6.0.3. - [Release notes](https://github.com/microsoft/TypeScript/releases) - [Commits](https://github.com/microsoft/TypeScript/compare/v5.9.3...v6.0.3) --- updated-dependencies: - dependency-name: typescript dependency-version: 6.0.3 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * test: stabilize flaky CI checks Co-authored-by: openhands <openhands@all-hands.dev> * test: harden Vitest browser globals Co-authored-by: openhands <openhands@all-hands.dev> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: openhands <openhands@all-hands.dev>
87 lines
2.2 KiB
TypeScript
87 lines
2.2 KiB
TypeScript
import { afterAll, afterEach, beforeAll, vi } from "vitest";
|
|
import { cleanup } from "@testing-library/react";
|
|
import { server } from "#/mocks/node";
|
|
import "@testing-library/jest-dom/vitest";
|
|
|
|
if (typeof HTMLCanvasElement !== "undefined") {
|
|
HTMLCanvasElement.prototype.getContext = vi.fn();
|
|
}
|
|
|
|
if (typeof HTMLElement !== "undefined") {
|
|
HTMLElement.prototype.scrollTo = vi.fn();
|
|
}
|
|
|
|
const windowStub =
|
|
typeof window === "undefined"
|
|
? ({ event: undefined } as unknown as Window & typeof globalThis)
|
|
: window;
|
|
|
|
vi.stubGlobal("window", windowStub);
|
|
windowStub.scrollTo = vi.fn();
|
|
|
|
if (typeof requestAnimationFrame === "undefined") {
|
|
vi.stubGlobal("requestAnimationFrame", (callback: FrameRequestCallback) =>
|
|
setTimeout(() => callback(0), 0),
|
|
);
|
|
vi.stubGlobal(
|
|
"cancelAnimationFrame",
|
|
(timeoutId: ReturnType<typeof setTimeout>) => clearTimeout(timeoutId),
|
|
);
|
|
}
|
|
|
|
// Mock ResizeObserver for test environment
|
|
class MockResizeObserver {
|
|
observe = vi.fn();
|
|
|
|
unobserve = vi.fn();
|
|
|
|
disconnect = vi.fn();
|
|
}
|
|
|
|
// Mock the i18n provider
|
|
vi.mock("react-i18next", async (importOriginal) => ({
|
|
...(await importOriginal<typeof import("react-i18next")>()),
|
|
useTranslation: () => ({
|
|
t: (key: string) => key,
|
|
i18n: {
|
|
language: "en",
|
|
exists: () => false,
|
|
},
|
|
}),
|
|
}));
|
|
|
|
vi.mock("#/hooks/use-is-on-tos-page", () => ({
|
|
useIsOnTosPage: () => false,
|
|
}));
|
|
|
|
vi.mock("#/hooks/use-is-on-intermediate-page", () => ({
|
|
useIsOnIntermediatePage: () => false,
|
|
}));
|
|
|
|
// Mock useRevalidator from react-router to allow direct store manipulation
|
|
// in tests instead of mocking useSelectedOrganizationId hook
|
|
vi.mock("react-router", async (importOriginal) => ({
|
|
...(await importOriginal<typeof import("react-router")>()),
|
|
useRevalidator: () => ({
|
|
revalidate: vi.fn(),
|
|
}),
|
|
}));
|
|
|
|
// Import the Zustand mock to enable automatic store resets
|
|
vi.mock("zustand");
|
|
|
|
// Mock requests during tests
|
|
beforeAll(() => {
|
|
server.listen({ onUnhandledRequest: "bypass" });
|
|
vi.stubGlobal("ResizeObserver", MockResizeObserver);
|
|
});
|
|
afterEach(() => {
|
|
server.resetHandlers();
|
|
// Cleanup the document body after each test
|
|
cleanup();
|
|
});
|
|
afterAll(() => {
|
|
server.close();
|
|
vi.unstubAllGlobals();
|
|
});
|