(obj, method)
| 21 | * @param {keyof T} method |
| 22 | */ |
| 23 | export function logCall(obj, method) { |
| 24 | let old = obj[method]; |
| 25 | obj[method] = function (...args) { |
| 26 | let c = ''; |
| 27 | for (let i = 0; i < args.length; i++) { |
| 28 | if (c) c += ', '; |
| 29 | c += serialize(args[i]); |
| 30 | } |
| 31 | |
| 32 | let operation; |
| 33 | switch (method) { |
| 34 | case 'removeChild': { |
| 35 | operation = `${serialize(c)}.remove()`; |
| 36 | break; |
| 37 | } |
| 38 | case 'insertBefore': { |
| 39 | if (args[1] === null && args.length === 2) { |
| 40 | operation = `${serialize(this)}.appendChild(${serialize(args[0])})`; |
| 41 | } else { |
| 42 | operation = `${serialize(this)}.${String(method)}(${c})`; |
| 43 | } |
| 44 | break; |
| 45 | } |
| 46 | default: { |
| 47 | operation = `${serialize(this)}.${String(method)}(${c})`; |
| 48 | break; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | log.push(operation); |
| 53 | return old.apply(this, args); |
| 54 | }; |
| 55 | |
| 56 | return () => (obj[method] = old); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Return log object |
no test coverage detected
searching dependent graphs…