Skip to content

Commit

Permalink
Add callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole White committed Feb 19, 2024
1 parent d6fd640 commit 8fe60a7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/handlers/testing/exec/components/progress/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function TestRow(props: {
);
}

const App = () => {
const App = (props: { onListenersCreated: () => void }) => {
const [consoleLogs, setConsoleLogs] = useState<ConsoleLog[]>([]);
const [uncaughtErrors, setUncaughtErrors] = useState<UncaughtError[]>([]);
const [evals, setEvals] = useState<Evaluation[]>([]);
Expand Down Expand Up @@ -174,6 +174,8 @@ const App = () => {
emitter.on(EventName.EVALUATION, evalListener);
emitter.on(EventName.RUN_ENDED, runEndListener);

props.onListenersCreated();

return () => {
emitter.off(EventName.CONSOLE_LOG, consoleLogListener);
emitter.off(EventName.UNCAUGHT_ERROR, uncaughtErrorListener);
Expand Down Expand Up @@ -237,4 +239,5 @@ const App = () => {
);
};

export const renderTestProgress = () => render(<App />);
export const renderTestProgress = (args: { onListenersCreated: () => void }) =>
render(<App onListenersCreated={args.onListenersCreated} />);
11 changes: 6 additions & 5 deletions src/handlers/testing/exec/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,13 @@ export async function exec(args: {
port: number;
exit1OnEvaluationFailure: boolean;
}) {
renderTestProgress();
let listenersCreated = false;
renderTestProgress({ onListenersCreated: () => (listenersCreated = true) });

// Wait for listeners to be set up in the progress component
await new Promise((resolve) => {
setTimeout(resolve, 10);
});
// Wait for listeners to be created before starting the server
while (!listenersCreated) {
await new Promise((resolve) => setTimeout(resolve, 10));
}

const runManager = new RunManager({
apiKey: args.apiKey,
Expand Down

0 comments on commit 8fe60a7

Please sign in to comment.