|
1 | | -import process, { version, nextTick } from 'process' |
2 | | -import { promisify } from 'util' |
| 1 | +import process, { version } from 'process' |
3 | 2 |
|
4 | 3 | import test from 'ava' |
5 | 4 |
|
6 | 5 | // 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' |
8 | 7 | 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' |
14 | 9 | import { removeProcessListeners } from '../helpers/remove.js' |
15 | 10 |
|
16 | | -const pNextTick = promisify(nextTick) |
17 | 11 | removeProcessListeners() |
18 | 12 |
|
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 | | - |
51 | 13 | test.serial('exit process if "exit: true"', async (t) => { |
52 | 14 | const stopLogging = startExitLogging({ exit: true }) |
53 | 15 |
|
@@ -95,57 +57,3 @@ test.serial('exit process by default', async (t) => { |
95 | 57 |
|
96 | 58 | stopLogging() |
97 | 59 | }) |
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 | | -) |
0 commit comments