(
options: {
url?: string;
method?: string;
response?: HTTPResponse;
failure?: HTTPRequest['failure'];
resourceType?: string;
hasPostData?: boolean;
postData?: string;
fetchPostData?: Promise<string>;
stableId?: number;
navigationRequest?: boolean;
frame?: Frame;
redirectChain?: HTTPRequest[];
headers?: Record<string, string>;
} = {},
)
| 151 | } |
| 152 | |
| 153 | export function getMockRequest( |
| 154 | options: { |
| 155 | url?: string; |
| 156 | method?: string; |
| 157 | response?: HTTPResponse; |
| 158 | failure?: HTTPRequest['failure']; |
| 159 | resourceType?: string; |
| 160 | hasPostData?: boolean; |
| 161 | postData?: string; |
| 162 | fetchPostData?: Promise<string>; |
| 163 | stableId?: number; |
| 164 | navigationRequest?: boolean; |
| 165 | frame?: Frame; |
| 166 | redirectChain?: HTTPRequest[]; |
| 167 | headers?: Record<string, string>; |
| 168 | } = {}, |
| 169 | ): HTTPRequest { |
| 170 | return { |
| 171 | url() { |
| 172 | return options.url ?? 'http://example.com'; |
| 173 | }, |
| 174 | method() { |
| 175 | return options.method ?? 'GET'; |
| 176 | }, |
| 177 | fetchPostData() { |
| 178 | return options.fetchPostData ?? Promise.reject(); |
| 179 | }, |
| 180 | hasPostData() { |
| 181 | return options.hasPostData ?? false; |
| 182 | }, |
| 183 | postData() { |
| 184 | return options.postData; |
| 185 | }, |
| 186 | response() { |
| 187 | return options.response ?? null; |
| 188 | }, |
| 189 | failure() { |
| 190 | return options.failure?.() ?? null; |
| 191 | }, |
| 192 | resourceType() { |
| 193 | return options.resourceType ?? 'document'; |
| 194 | }, |
| 195 | headers(): Record<string, string> { |
| 196 | return ( |
| 197 | options.headers ?? { |
| 198 | 'content-size': '10', |
| 199 | } |
| 200 | ); |
| 201 | }, |
| 202 | redirectChain(): HTTPRequest[] { |
| 203 | // Puppeteer returns a fresh copy on every call (HTTPRequest returns |
| 204 | // `this._redirectChain.slice()`); mirror that so formatters can't share |
| 205 | // and accidentally mutate the same array across calls. |
| 206 | return [...(options.redirectChain ?? [])]; |
| 207 | }, |
| 208 | isNavigationRequest() { |
| 209 | return options.navigationRequest ?? false; |
| 210 | }, |
no outgoing calls
no test coverage detected