MCPcopy
hub / github.com/Rich-Harris/degit / createMockGit

Function createMockGit

test/helpers.ts:21–51  ·  view source on GitHub ↗
(stubs = {})

Source from the content-addressed store, hash-verified

19}
20
21export function createMockGit(stubs = {}) {
22 const calls = [];
23 const getGitUrl = (repo, transport = repo.transport) =>
24 transport === 'ssh' ? repo.ssh : repo.url;
25 const resolveStub = async (call, ...args) => {
26 if (!Object.hasOwn(stubs, call)) {
27 return Promise.reject(new Error(`Unexpected git call: ${call}`));
28 }
29
30 const stub = stubs[call];
31 if (typeof stub === 'function') {
32 return stub(...args);
33 }
34
35 return Promise.resolve(stub);
36 };
37
38 const fetchRefs = async (repo) => {
39 const call = `fetchRefs ${getGitUrl(repo)}`;
40 calls.push(call);
41 return resolveStub(call, repo);
42 };
43
44 const clone = async (repo, dest, ref, transport) => {
45 const call = `clone ${getGitUrl(repo, transport)} ${dest}${ref ? ` ${ref}` : ''}`;
46 calls.push(call);
47 return resolveStub(call, repo, dest, ref, transport);
48 };
49
50 return { calls, fn: { clone, fetchRefs } };
51}
52
53export function createMockFetch(steps) {
54 const calls = [];

Callers 3

cloneAndReadFileFunction · 0.50
cloneAndExpectTarContentFunction · 0.50
index.test.tsFile · 0.50

Calls

no outgoing calls

Tested by 2

cloneAndReadFileFunction · 0.40
cloneAndExpectTarContentFunction · 0.40

Used in the wild real call sites across dependent graphs

searching dependent graphs…