MCPcopy
hub / github.com/vercel/next.js / MockedResponse

Class MockedResponse

packages/next/src/server/lib/mock-request.ts:148–466  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146}
147
148export class MockedResponse extends Stream.Writable implements ServerResponse {
149 public statusCode: number
150 public statusMessage: string = ''
151 public finished = false
152 public headersSent = false
153 public readonly socket: Socket | null
154
155 /**
156 * A promise that resolves to `true` when the response has been streamed.
157 *
158 * @internal - used internally by Next.js
159 */
160 public readonly hasStreamed: Promise<boolean>
161
162 /**
163 * A list of buffers that have been written to the response.
164 *
165 * @internal - used internally by Next.js
166 */
167 public readonly buffers: Buffer[] = []
168
169 /**
170 * The headers object that contains the headers that were initialized on the
171 * response and any that were added subsequently.
172 *
173 * @internal - used internally by Next.js
174 */
175 public readonly headers: Headers
176
177 private resWriter: MockedResponseOptions['resWriter']
178 private maximumResponseBody?: number
179 private totalSize: number = 0
180
181 public readonly headPromise: Promise<void>
182 private headPromiseResolve?: () => void
183
184 constructor(res: MockedResponseOptions = {}) {
185 super()
186
187 this.statusCode = res.statusCode ?? 200
188 this.socket = res.socket ?? null
189 this.headers = res.headers
190 ? fromNodeOutgoingHttpHeaders(res.headers)
191 : new Headers()
192 this.maximumResponseBody = res.maximumResponseBody
193
194 this.headPromise = new Promise<void>((resolve) => {
195 this.headPromiseResolve = resolve
196 })
197
198 // Attach listeners for the `finish`, `end`, and `error` events to the
199 // `MockedResponse` instance.
200 this.hasStreamed = new Promise<boolean>((resolve, reject) => {
201 this.on('finish', () => resolve(true))
202 this.on('end', () => resolve(true))
203 this.on('error', (err) => reject(err))
204 }).then((val) => {
205 this.headPromiseResolve?.()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected