(t, {
config,
mocks = {},
files,
error,
command,
...opts
} = {})
| 58 | }, { replace: true }) |
| 59 | |
| 60 | const mockExitHandler = async (t, { |
| 61 | config, |
| 62 | mocks = {}, |
| 63 | files, |
| 64 | error, |
| 65 | command, |
| 66 | ...opts |
| 67 | } = {}) => { |
| 68 | const errors = [] |
| 69 | |
| 70 | mocks['{LIB}/utils/error-message.js'] = { |
| 71 | ...errorMessage, |
| 72 | errorMessage: (err) => ({ |
| 73 | ...errorMessage.errorMessage(err), |
| 74 | ...(files ? { files } : {}), |
| 75 | }), |
| 76 | getError: (...args) => ({ |
| 77 | ...errorMessage.getError(...args), |
| 78 | ...(files ? { files } : {}), |
| 79 | }), |
| 80 | } |
| 81 | |
| 82 | if (error) { |
| 83 | mocks[`{LIB}/commands/root.js`] = class { |
| 84 | async exec () { |
| 85 | throw error |
| 86 | } |
| 87 | } |
| 88 | mocks[`{LIB}/commands/exec.js`] = class extends ExecCommand { |
| 89 | async exec (...args) { |
| 90 | await super.exec(...args) |
| 91 | throw error |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | const { npm, ...rest } = await loadMockNpm(t, { |
| 97 | ...opts, |
| 98 | mocks, |
| 99 | config: (dirs) => ({ |
| 100 | loglevel: 'notice', |
| 101 | ...(typeof config === 'function' ? config(dirs) : config), |
| 102 | }), |
| 103 | globals: { |
| 104 | 'console.error': (err) => errors.push(err), |
| 105 | }, |
| 106 | }) |
| 107 | |
| 108 | const ExitHandler = tmock(t, '{LIB}/cli/exit-handler.js', mocks) |
| 109 | |
| 110 | const exitHandler = new ExitHandler({ process }) |
| 111 | exitHandler.registerUncaughtHandlers() |
| 112 | |
| 113 | if (npm) { |
| 114 | exitHandler.setNpm(npm) |
| 115 | } |
| 116 | |
| 117 | t.teardown(() => { |
no test coverage detected
searching dependent graphs…