Skip to content

Commit 394023e

Browse files
committed
Refactoring
1 parent e99d105 commit 394023e

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

test/helpers/exit.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import { startLogging } from './start.js'
1010
// `process.exit()` is being stubbed
1111
export const startProcessLogging = function (eventName, opts) {
1212
const processHandler = setProcessEvent(eventName)
13-
stubProcessExit()
14-
const { stopLogging } = startLogging(opts)
13+
const stopLogging = startExitLogging(opts)
1514
return stopProcessLogging.bind(
1615
undefined,
1716
eventName,
@@ -22,43 +21,31 @@ export const startProcessLogging = function (eventName, opts) {
2221

2322
const stopProcessLogging = function (eventName, stopLogging, processHandler) {
2423
stopLogging()
25-
unStubProcessExit()
2624
unsetProcessEvent(eventName, processHandler)
2725
}
2826

2927
// Start logging while `setTimeout()` and `process.exit()` are being stubbed
3028
export const startClockLogging = function (opts) {
3129
const clock = fakeTimers.install({ toFake: ['setTimeout'] })
32-
stubProcessExit()
33-
const { stopLogging } = startLogging(opts)
30+
const stopLogging = startExitLogging(opts)
3431
const stopLoggingA = stopClockLogging.bind(undefined, stopLogging, clock)
3532
return { clock, stopLogging: stopLoggingA }
3633
}
3734

3835
const stopClockLogging = function (stopLogging, clock) {
3936
stopLogging()
40-
unStubProcessExit()
4137
clock.uninstall()
4238
}
4339

4440
// Start logging while `process.exit()` is being stubbed
4541
export const startExitLogging = function (opts) {
46-
stubProcessExit()
42+
sinon.stub(process, 'exit')
4743
const { stopLogging } = startLogging(opts)
4844
return stopExitLogging.bind(undefined, stopLogging)
4945
}
5046

5147
const stopExitLogging = function (stopLogging) {
5248
stopLogging()
53-
unStubProcessExit()
54-
}
55-
56-
// Stub `process.exit()`
57-
const stubProcessExit = function () {
58-
sinon.stub(process, 'exit')
59-
}
60-
61-
const unStubProcessExit = function () {
6249
process.exit.restore()
6350
process.exitCode = undefined
6451
}

0 commit comments

Comments
 (0)