Function
stubModule
(path, name, fn, callsFake = () => {})
Source from the content-addressed store, hash-verified
| 6 | const stubbedCalls = {}; |
| 7 | |
| 8 | async function stubModule(path, name, fn, callsFake = () => {}) { |
| 9 | const imported = require(path); |
| 10 | const original = imported[name]; |
| 11 | imported[name] = (...args) => { |
| 12 | const calls = stubbedCalls[name] || (stubbedCalls[name] = []); |
| 13 | calls.push(args); |
| 14 | return callsFake(...args); |
| 15 | }; |
| 16 | await fn(); |
| 17 | imported.log = original; |
| 18 | } |
| 19 | |
| 20 | const test = (name, cb) => |
| 21 | ava(name, (t) => |