Skip to content

Commit c49bea9

Browse files
committed
chore: use 2 effects instead
1 parent e685c6e commit c49bea9

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/Reporter.tsx

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,8 @@ const CompletedTests: React.FC<{
9595
let testOutputs = completedTests.map(({ testResult, config }) => (
9696
<React.Fragment key={testResult.testFilePath + config.name}>
9797
<ResultHeader config={config} testResult={testResult} />
98-
<VerboseTestList
99-
testResult={testResult}
100-
globalConfig={globalConfig}
101-
/>
102-
<TestConsoleOutput
98+
<VerboseTestList testResult={testResult} globalConfig={globalConfig} />
99+
<TestConsoleOutput
103100
console={testResult.console}
104101
verbose={globalConfig.verbose}
105102
cwd={config.cwd}
@@ -219,6 +216,26 @@ const RunningTests: React.FC<{
219216
);
220217
};
221218

219+
const Exiter: React.FC<{ done: boolean }> = ({ done }) => {
220+
const { exit } = useApp();
221+
222+
const [shouldExit, setShouldExit] = React.useState(false);
223+
224+
React.useEffect(() => {
225+
if (done) {
226+
setShouldExit(true);
227+
}
228+
}, [done, exit]);
229+
230+
React.useEffect(() => {
231+
if (shouldExit) {
232+
exit();
233+
}
234+
}, [exit, shouldExit]);
235+
236+
return null;
237+
};
238+
222239
const Reporter: React.FC<Props> = ({
223240
register,
224241
globalConfig,
@@ -249,13 +266,6 @@ const Reporter: React.FC<Props> = ({
249266
} = state;
250267
const { estimatedTime = 0 } = options;
251268

252-
const { exit } = useApp();
253-
React.useEffect(() => {
254-
if (done) {
255-
setImmediate(exit);
256-
}
257-
}, [done, exit]);
258-
259269
const summary = (
260270
<Summary
261271
aggregatedResults={aggregatedResults}
@@ -280,6 +290,7 @@ const Reporter: React.FC<Props> = ({
280290
/>
281291
<RunningTests tests={currentTests} width={width} />
282292
{done ? null : summary}
293+
<Exiter done={done} />
283294
</Box>
284295
);
285296
};

0 commit comments

Comments
 (0)