Skip to content

Commit 80b1f9f

Browse files
committed
chore: use 2 effects instead
1 parent 5445038 commit 80b1f9f

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
@@ -216,6 +216,27 @@ const RunningTests: React.FC<{
216216
);
217217
};
218218

219+
const Exiter: React.FC<{ done: boolean }> = ({ done }) => {
220+
const { exit } = useApp();
221+
222+
const [shouldExit, setShouldExit] = React.useState(false);
223+
224+
// use a separate effect to ensure output is properly flushed. This _might_ be a bug in Ink, not sure
225+
React.useEffect(() => {
226+
if (done) {
227+
setShouldExit(true);
228+
}
229+
}, [done, exit]);
230+
231+
React.useEffect(() => {
232+
if (shouldExit) {
233+
exit();
234+
}
235+
}, [exit, shouldExit]);
236+
237+
return null;
238+
};
239+
219240
const Reporter: React.FC<Props> = ({
220241
register,
221242
globalConfig,
@@ -246,13 +267,6 @@ const Reporter: React.FC<Props> = ({
246267
} = state;
247268
const { estimatedTime = 0 } = options;
248269

249-
const { exit } = useApp();
250-
React.useEffect(() => {
251-
if (done) {
252-
setImmediate(exit);
253-
}
254-
}, [done, exit]);
255-
256270
const summary = (
257271
<Summary
258272
aggregatedResults={aggregatedResults}
@@ -277,6 +291,7 @@ const Reporter: React.FC<Props> = ({
277291
/>
278292
<RunningTests tests={currentTests} width={width} />
279293
{done ? null : summary}
294+
<Exiter done={done} />
280295
</Box>
281296
);
282297
};

0 commit comments

Comments
 (0)