MCPcopy Index your code
hub / github.com/nodejs/node / mockExitHandler

Function mockExitHandler

deps/npm/test/lib/cli/exit-handler.js:60–141  ·  view source on GitHub ↗
(t, {
  config,
  mocks = {},
  files,
  error,
  command,
  ...opts
} = {})

Source from the content-addressed store, hash-verified

58}, { replace: true })
59
60const 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(() => {

Callers 2

exit-handler.jsFile · 0.85
mockShelloutExitFunction · 0.85

Calls 10

setNpmMethod · 0.95
exitMethod · 0.95
tmockFunction · 0.85
loadMockNpmFunction · 0.50
pushMethod · 0.45
removeAllListenersMethod · 0.45
onceMethod · 0.45
thenMethod · 0.45
execMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…