(stubs = {})
| 19 | } |
| 20 | |
| 21 | export 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 | |
| 53 | export function createMockFetch(steps) { |
| 54 | const calls = []; |
no outgoing calls
searching dependent graphs…