Some checks failed
Dev Deployment (Zero Downtime) / deploy-dev (push) Failing after 7m26s
Remove unused imports, replace `any` types with proper interfaces in directus.ts and i18n-loader.ts, exclude scripts/ and coverage/ from ESLint, and fix unused variable warnings across the codebase. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import "@testing-library/jest-dom";
|
|
import { Request, Response, Headers } from "node-fetch";
|
|
|
|
// Mock matchMedia
|
|
Object.defineProperty(window, "matchMedia", {
|
|
writable: true,
|
|
value: jest.fn().mockImplementation((query) => ({
|
|
matches: false,
|
|
media: query,
|
|
onchange: null,
|
|
addListener: jest.fn(),
|
|
removeListener: jest.fn(),
|
|
addEventListener: jest.fn(),
|
|
removeEventListener: jest.fn(),
|
|
dispatchEvent: jest.fn(),
|
|
})),
|
|
});
|
|
|
|
// Mock IntersectionObserver
|
|
class MockIntersectionObserver {
|
|
observe = jest.fn();
|
|
unobserve = jest.fn();
|
|
disconnect = jest.fn();
|
|
}
|
|
|
|
Object.defineProperty(window, "IntersectionObserver", {
|
|
writable: true,
|
|
configurable: true,
|
|
value: MockIntersectionObserver,
|
|
});
|
|
|
|
// Polyfill Headers/Request/Response
|
|
if (!global.Headers) {
|
|
// @ts-expect-error - Polyfilling global Headers for jest environment
|
|
global.Headers = Headers;
|
|
}
|
|
if (!global.Request) {
|
|
// @ts-expect-error - Polyfilling global Request for jest environment
|
|
global.Request = Request;
|
|
}
|
|
if (!global.Response) {
|
|
// @ts-expect-error - Polyfilling global Response for jest environment
|
|
global.Response = Response;
|
|
}
|
|
|
|
// Mock NextResponse
|
|
jest.mock('next/server', () => {
|
|
const actual = jest.requireActual('next/server');
|
|
return {
|
|
...actual,
|
|
NextResponse: {
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
json: (data: Record<string, unknown>, init?: any) => {
|
|
// Use global Response from whatwg-fetch
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
const res = new (global as any).Response(JSON.stringify(data), init);
|
|
res.headers.set('Content-Type', 'application/json');
|
|
return res;
|
|
},
|
|
next: () => ({ headers: new Headers() }),
|
|
redirect: (_url: string) => ({ headers: new Headers(), status: 302 }),
|
|
},
|
|
};
|
|
});
|
|
|
|
// Env vars for tests
|
|
process.env.DIRECTUS_URL = "http://localhost:8055";
|
|
process.env.DIRECTUS_TOKEN = "test-token";
|
|
process.env.NEXT_PUBLIC_SITE_URL = "http://localhost:3000";
|