Skip to content

Commit 4e34d8f

Browse files
committed
chore: use 2 effects instead
1 parent 5d17211 commit 4e34d8f

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/Reporter.tsx

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,27 @@ const RunningTests: React.FC<{
222222
);
223223
};
224224

225+
const Exiter: React.FC<{ done: boolean }> = ({ done }) => {
226+
const { exit } = useApp();
227+
228+
const [shouldExit, setShouldExit] = React.useState(false);
229+
230+
// use a separate effect to ensure output is properly flushed. This _might_ be a bug in Ink, not sure
231+
React.useEffect(() => {
232+
if (done) {
233+
setShouldExit(true);
234+
}
235+
}, [done, exit]);
236+
237+
React.useEffect(() => {
238+
if (shouldExit) {
239+
exit();
240+
}
241+
}, [exit, shouldExit]);
242+
243+
return null;
244+
};
245+
225246
const Reporter: React.FC<Props> = ({
226247
register,
227248
globalConfig,
@@ -247,13 +268,6 @@ const Reporter: React.FC<Props> = ({
247268
state;
248269
const { estimatedTime = 0 } = options;
249270

250-
const { exit } = useApp();
251-
React.useEffect(() => {
252-
if (done) {
253-
setImmediate(exit);
254-
}
255-
}, [done, exit]);
256-
257271
const summary = (
258272
<Summary
259273
aggregatedResults={aggregatedResults}
@@ -278,6 +292,7 @@ const Reporter: React.FC<Props> = ({
278292
/>
279293
<RunningTests tests={currentTests} width={width} />
280294
{done ? null : summary}
295+
<Exiter done={done} />
281296
</Box>
282297
);
283298
};

0 commit comments

Comments
 (0)