UNPKG

mock-argv

Version:

Temporarily overrides the command line arguments. This is useful for testing.

11 lines 321 B
export default async (...args) => { const argv = typeof args[0] === "function" ? [] : args[0]; const func = typeof args[0] === "function" ? args[0] : args[1]; const oldArgv = process.argv; process.argv = [...oldArgv.slice(0, 2), ...argv]; try { await func(); } finally { process.argv = oldArgv; } };