The endpoint and its exposure control ship together on purpose. The moment /api/flags exists, app/api/[...path] forwards it — and the response names every unreleased feature the codebase knows about, along with whether it is on. Publishing that is the opposite of shipping dark. Denied on an exact first-segment match, not a prefix, so /api/flagship does not go down with /api/flags. Next reads the endpoint server-side over the Docker network, which never transits the public proxy. jest.setup.js now guards its browser globals. It runs for every suite, including the one that declares @jest-environment node to exercise the route handler — NextRequest needs Fetch API globals jsdom lacks, and there is no window there to define matchMedia on. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015mWQnpye9F299NVRCCSRvj
63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
// Learn more: https://github.com/testing-library/jest-dom
|
|
import '@testing-library/jest-dom';
|
|
|
|
// Mock Next.js router
|
|
jest.mock('next/navigation', () => ({
|
|
useRouter: () => ({
|
|
push: jest.fn(),
|
|
replace: jest.fn(),
|
|
prefetch: jest.fn(),
|
|
}),
|
|
usePathname: () => '/',
|
|
useSearchParams: () => new URLSearchParams(),
|
|
}));
|
|
|
|
// Everything below this line is browser furniture, and this file runs for
|
|
// every suite — including the ones that declare `@jest-environment node` to
|
|
// test route handlers, where NextRequest needs Fetch API globals jsdom does
|
|
// not provide. There is no `window` there, so guard rather than assume one.
|
|
if (typeof window !== 'undefined') {
|
|
|
|
// Mock window.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(),
|
|
})),
|
|
});
|
|
|
|
// jsdom implements neither of these; the school detail views use both
|
|
// (IntersectionObserver for the scroll-spy and the hero-CTA tracker,
|
|
// scrollTo for the "back to top" control).
|
|
global.IntersectionObserver = class {
|
|
constructor(callback) {
|
|
this.callback = callback;
|
|
}
|
|
observe() {}
|
|
unobserve() {}
|
|
disconnect() {}
|
|
takeRecords() {
|
|
return [];
|
|
}
|
|
};
|
|
|
|
window.scrollTo = jest.fn();
|
|
|
|
// Mock localStorage
|
|
const localStorageMock = {
|
|
getItem: jest.fn(),
|
|
setItem: jest.fn(),
|
|
removeItem: jest.fn(),
|
|
clear: jest.fn(),
|
|
};
|
|
global.localStorage = localStorageMock;
|
|
|
|
} // end: browser-only globals
|