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

Function stubRegistryFetch

packages/container/test/unit.test.ts:49–85  ·  view source on GitHub ↗
(
  fetchMock: ReturnType<typeof vi.fn>,
  options: { repositoryStatus?: number; mintStatus?: number } = {}
)

Source from the content-addressed store, hash-verified

47}
48
49function stubRegistryFetch(
50 fetchMock: ReturnType<typeof vi.fn>,
51 options: { repositoryStatus?: number; mintStatus?: number } = {}
52) {
53 const repositoryStatus = options.repositoryStatus ?? 200;
54 const mintStatus = options.mintStatus ?? 200;
55 fetchMock.mockImplementation((url: string | URL) => {
56 const href = String(url);
57 if (href.includes('/v1/projects/') && href.includes('/token')) {
58 const projectId =
59 href.match(/\/projects\/([^/?]+)\/token/)?.[1] ?? 'prj_test';
60 const token = fakeOidcToken({
61 project_id: projectId,
62 owner_id: 'team_test',
63 });
64 return Promise.resolve({
65 ok: mintStatus >= 200 && mintStatus < 300,
66 status: mintStatus,
67 json: async () => ({ token }),
68 text: async () =>
69 mintStatus === 403 ? 'Forbidden' : JSON.stringify({ token }),
70 });
71 }
72 if (href.includes('/v1/vcr/repository')) {
73 return Promise.resolve({
74 ok: repositoryStatus >= 200 && repositoryStatus < 300,
75 status: repositoryStatus,
76 text: async () => '',
77 });
78 }
79 return Promise.resolve({
80 ok: true,
81 status: 200,
82 text: async () => '',
83 });
84 });
85}
86
87/** Fake child process that exits with a failure code. */
88function fakeChildFailure(stderr = '') {

Callers 2

runDockerfileBuildFunction · 0.85
unit.test.tsFile · 0.85

Calls 3

fakeOidcTokenFunction · 0.85
matchMethod · 0.45
resolveMethod · 0.45

Tested by

no test coverage detected