MCPcopy Create free account
hub / github.com/vercel/vercel / testPath

Function testPath

packages/cli/test/dev/utils.ts:349–392  ·  view source on GitHub ↗
(
  isDev: boolean,
  origin: string,
  status: number,
  path: string,
  expectedText: string | Function | RegExp,
  expectedHeaders = {},
  fetchOpts: FetchOptions = {}
)

Source from the content-addressed store, hash-verified

347}
348
349export async function testPath(
350 isDev: boolean,
351 origin: string,
352 status: number,
353 path: string,
354 expectedText: string | Function | RegExp,
355 expectedHeaders = {},
356 fetchOpts: FetchOptions = {}
357) {
358 const opts: FetchOptions = {
359 retries: isCI ? 5 : 0,
360 ...fetchOpts,
361 redirect: 'manual',
362 status,
363 };
364 const url = `${origin}${path}`;
365 const res = await fetchWithRetry(url, opts);
366 const msg = `Testing response from ${fetchOpts.method || 'GET'} ${url}`;
367
368 console.log(msg);
369 expect(res.status, getEnvironmentMessage(isDev)).toBe(status);
370 validateResponseHeaders(res);
371
372 if (typeof expectedText === 'string') {
373 const actualText = await res.text();
374 expect(actualText.trim(), getEnvironmentMessage(isDev)).toBe(
375 expectedText.trim()
376 );
377 } else if (typeof expectedText === 'function') {
378 const actualText = await res.text();
379 await expectedText(actualText, res, isDev);
380 } else if (expectedText instanceof RegExp) {
381 const actualText = await res.text();
382 expectedText.lastIndex = 0; // reset since we test twice
383 expect(actualText, getEnvironmentMessage(isDev)).toMatch(expectedText);
384 }
385
386 if (expectedHeaders) {
387 Object.entries(expectedHeaders).forEach(([key, expectedValue]) => {
388 const actualValue = res.headers.get(key);
389 expect(actualValue, getEnvironmentMessage(isDev)).toBe(expectedValue);
390 });
391 }
392}
393
394function getEnvironmentMessage(isDev: boolean): string {
395 if (isDev) {

Callers 6

helperTestPathFunction · 0.85

Calls 6

fetchWithRetryFunction · 0.85
getEnvironmentMessageFunction · 0.85
validateResponseHeadersFunction · 0.85
textMethod · 0.80
getMethod · 0.65
logMethod · 0.45

Tested by

no test coverage detected