File tree Expand file tree Collapse file tree 2 files changed +34
-29
lines changed
Expand file tree Collapse file tree 2 files changed +34
-29
lines changed Original file line number Diff line number Diff line change @@ -10,43 +10,16 @@ import { EXIT_TIMEOUT, EXIT_CODE } from '../src/exit.js'
1010import { emit } from './helpers/events.js'
1111import {
1212 stubProcessClock ,
13- stubProcessExit ,
1413 unStubProcessClock ,
15- unStubProcessExit ,
14+ startExitLogging ,
15+ startProcessLogging ,
1616} from './helpers/exit.js'
17- import { setProcessEvent , unsetProcessEvent } from './helpers/process.js'
1817import { removeProcessListeners } from './helpers/remove.js'
1918import { startLogging } from './helpers/start.js'
2019
2120const pNextTick = promisify ( nextTick )
2221removeProcessListeners ( )
2322
24- const startProcessLogging = function ( eventName , opts ) {
25- const processHandler = setProcessEvent ( eventName )
26- const stopLogging = startExitLogging ( opts )
27- return stopProcessLogging . bind (
28- undefined ,
29- eventName ,
30- stopLogging ,
31- processHandler ,
32- )
33- }
34-
35- const stopProcessLogging = function ( eventName , stopLogging , processHandler ) {
36- stopLogging ( )
37- unsetProcessEvent ( eventName , processHandler )
38- }
39-
40- const startExitLogging = function ( opts ) {
41- stubProcessExit ( )
42- return stopExitLogging . bind ( undefined , startLogging ( opts ) . stopLogging )
43- }
44-
45- const stopExitLogging = function ( stopLogging ) {
46- stopLogging ( )
47- unStubProcessExit ( )
48- }
49-
5023test . serial ( 'call process.exit() after a timeout' , async ( t ) => {
5124 const clock = stubProcessClock ( )
5225 const { stopLogging } = startLogging ( { exit : true } )
Original file line number Diff line number Diff line change @@ -3,6 +3,38 @@ import process from 'process'
33import fakeTimers from '@sinonjs/fake-timers'
44import sinon from 'sinon'
55
6+ import { setProcessEvent , unsetProcessEvent } from './process.js'
7+ import { startLogging } from './start.js'
8+
9+ // Start logging while a specific process event handler is being used, and
10+ // `process.exit()` is being stubbed
11+ export const startProcessLogging = function ( eventName , opts ) {
12+ const processHandler = setProcessEvent ( eventName )
13+ const stopLogging = startExitLogging ( opts )
14+ return stopProcessLogging . bind (
15+ undefined ,
16+ eventName ,
17+ stopLogging ,
18+ processHandler ,
19+ )
20+ }
21+
22+ const stopProcessLogging = function ( eventName , stopLogging , processHandler ) {
23+ stopLogging ( )
24+ unsetProcessEvent ( eventName , processHandler )
25+ }
26+
27+ // Start logging while `process.exit()` is being stubbed
28+ export const startExitLogging = function ( opts ) {
29+ stubProcessExit ( )
30+ return stopExitLogging . bind ( undefined , startLogging ( opts ) . stopLogging )
31+ }
32+
33+ const stopExitLogging = function ( stopLogging ) {
34+ stopLogging ( )
35+ unStubProcessExit ( )
36+ }
37+
638// Stub `setTimeout()` and `process.exit()`
739export const stubProcessClock = function ( ) {
840 stubProcessExit ( )
You can’t perform that action at this time.
0 commit comments