Skip to content

Commit aaa86ff

Browse files
committed
Split file
1 parent 5efed35 commit aaa86ff

File tree

3 files changed

+113
-95
lines changed

3 files changed

+113
-95
lines changed

test/exit/clock.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import process, { nextTick } from 'process'
2+
import { promisify } from 'util'
3+
4+
import test from 'ava'
5+
6+
// eslint-disable-next-line no-restricted-imports
7+
import { EXIT_TIMEOUT, EXIT_CODE } from '../../src/exit.js'
8+
import { emit } from '../helpers/events.js'
9+
import { startClockLogging } from '../helpers/exit.js'
10+
import { removeProcessListeners } from '../helpers/remove.js'
11+
12+
const pNextTick = promisify(nextTick)
13+
removeProcessListeners()
14+
15+
const advanceClock = function (t, clock) {
16+
t.deepEqual(process.exit.args, [])
17+
clock.tick(EXIT_TIMEOUT)
18+
t.deepEqual(process.exit.args, [[EXIT_CODE]])
19+
}
20+
21+
test.serial('call process.exit() after a timeout', async (t) => {
22+
const { clock, stopLogging } = startClockLogging({ exit: true })
23+
24+
await emit('uncaughtException')
25+
advanceClock(t, clock)
26+
27+
stopLogging()
28+
})
29+
30+
test.serial('wait for async onError() before exiting', async (t) => {
31+
const onErrorDuration = 1e5
32+
const { clock, stopLogging } = startClockLogging({
33+
async onError() {
34+
await promisify(setTimeout)(onErrorDuration)
35+
},
36+
exit: true,
37+
})
38+
39+
await emit('uncaughtException')
40+
clock.tick(onErrorDuration)
41+
await pNextTick()
42+
advanceClock(t, clock)
43+
44+
stopLogging()
45+
})

test/exit/main.js

Lines changed: 3 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,15 @@
1-
import process, { version, nextTick } from 'process'
2-
import { promisify } from 'util'
1+
import process, { version } from 'process'
32

43
import test from 'ava'
54

65
// eslint-disable-next-line no-restricted-imports
7-
import { EXIT_TIMEOUT, EXIT_CODE } from '../../src/exit.js'
6+
import { EXIT_CODE } from '../../src/exit.js'
87
import { emit } from '../helpers/events.js'
9-
import {
10-
startClockLogging,
11-
startExitLogging,
12-
startProcessLogging,
13-
} from '../helpers/exit.js'
8+
import { startExitLogging } from '../helpers/exit.js'
149
import { removeProcessListeners } from '../helpers/remove.js'
1510

16-
const pNextTick = promisify(nextTick)
1711
removeProcessListeners()
1812

19-
const advanceClock = function (t, clock) {
20-
t.deepEqual(process.exit.args, [])
21-
clock.tick(EXIT_TIMEOUT)
22-
t.deepEqual(process.exit.args, [[EXIT_CODE]])
23-
}
24-
25-
test.serial('call process.exit() after a timeout', async (t) => {
26-
const { clock, stopLogging } = startClockLogging({ exit: true })
27-
28-
await emit('uncaughtException')
29-
advanceClock(t, clock)
30-
31-
stopLogging()
32-
})
33-
34-
test.serial('wait for async onError() before exiting', async (t) => {
35-
const onErrorDuration = 1e5
36-
const { clock, stopLogging } = startClockLogging({
37-
async onError() {
38-
await promisify(setTimeout)(onErrorDuration)
39-
},
40-
exit: true,
41-
})
42-
43-
await emit('uncaughtException')
44-
clock.tick(onErrorDuration)
45-
await pNextTick()
46-
advanceClock(t, clock)
47-
48-
stopLogging()
49-
})
50-
5113
test.serial('exit process if "exit: true"', async (t) => {
5214
const stopLogging = startExitLogging({ exit: true })
5315

@@ -95,57 +57,3 @@ test.serial('exit process by default', async (t) => {
9557

9658
stopLogging()
9759
})
98-
99-
test.serial(
100-
'does not exit process by default if there are other listeners',
101-
async (t) => {
102-
const stopLogging = startProcessLogging('uncaughtException', {
103-
exit: undefined,
104-
})
105-
106-
await emit('uncaughtException')
107-
t.is(process.exitCode, undefined)
108-
109-
stopLogging()
110-
},
111-
)
112-
113-
test.serial(
114-
'exits process if there are other listeners but "exit: true"',
115-
async (t) => {
116-
const stopLogging = startProcessLogging('uncaughtException', { exit: true })
117-
118-
await emit('uncaughtException')
119-
t.is(process.exitCode, EXIT_CODE)
120-
121-
stopLogging()
122-
},
123-
)
124-
125-
test.serial(
126-
'exits process by default if there are other listeners for other events',
127-
async (t) => {
128-
const stopLogging = startProcessLogging('unhandledRejection', {
129-
exit: undefined,
130-
})
131-
132-
await emit('uncaughtException')
133-
t.is(process.exitCode, EXIT_CODE)
134-
135-
stopLogging()
136-
},
137-
)
138-
139-
test.serial(
140-
'does not exit process by default if there are other listeners for other events but "exit: false"',
141-
async (t) => {
142-
const stopLogging = startProcessLogging('unhandledRejection', {
143-
exit: false,
144-
})
145-
146-
await emit('uncaughtException')
147-
t.is(process.exitCode, undefined)
148-
149-
stopLogging()
150-
},
151-
)

test/exit/process.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import process from 'process'
2+
3+
import test from 'ava'
4+
5+
// eslint-disable-next-line no-restricted-imports
6+
import { EXIT_CODE } from '../../src/exit.js'
7+
import { emit } from '../helpers/events.js'
8+
import { startProcessLogging } from '../helpers/exit.js'
9+
import { removeProcessListeners } from '../helpers/remove.js'
10+
11+
removeProcessListeners()
12+
13+
test.serial(
14+
'does not exit process by default if there are other listeners',
15+
async (t) => {
16+
const stopLogging = startProcessLogging('uncaughtException', {
17+
exit: undefined,
18+
})
19+
20+
await emit('uncaughtException')
21+
t.is(process.exitCode, undefined)
22+
23+
stopLogging()
24+
},
25+
)
26+
27+
test.serial(
28+
'exits process if there are other listeners but "exit: true"',
29+
async (t) => {
30+
const stopLogging = startProcessLogging('uncaughtException', { exit: true })
31+
32+
await emit('uncaughtException')
33+
t.is(process.exitCode, EXIT_CODE)
34+
35+
stopLogging()
36+
},
37+
)
38+
39+
test.serial(
40+
'exits process by default if there are other listeners for other events',
41+
async (t) => {
42+
const stopLogging = startProcessLogging('unhandledRejection', {
43+
exit: undefined,
44+
})
45+
46+
await emit('uncaughtException')
47+
t.is(process.exitCode, EXIT_CODE)
48+
49+
stopLogging()
50+
},
51+
)
52+
53+
test.serial(
54+
'does not exit process by default if there are other listeners for other events but "exit: false"',
55+
async (t) => {
56+
const stopLogging = startProcessLogging('unhandledRejection', {
57+
exit: false,
58+
})
59+
60+
await emit('uncaughtException')
61+
t.is(process.exitCode, undefined)
62+
63+
stopLogging()
64+
},
65+
)

0 commit comments

Comments
 (0)