// Node test environment setup (API route + lib tests) // Provide missing Web APIs used by Next.js route handlers. // Streams try { const webStreams = require("node:stream/web"); if (!global.TransformStream) global.TransformStream = webStreams.TransformStream; if (!global.ReadableStream) global.ReadableStream = webStreams.ReadableStream; if (!global.WritableStream) global.WritableStream = webStreams.WritableStream; } catch { // ignore } // Ensure fetch stack exists (Node 18+). If missing, tests will fail loudly. // We intentionally do not polyfill via extra deps here. if (!global.fetch || !global.Request || !global.Response || !global.Headers) { // eslint-disable-next-line no-console console.warn( "[jest] Missing fetch globals (fetch/Request/Response/Headers). Node should provide these." ); }