-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a secton that waits until the app is ready
Signed-off-by: ytimocin <[email protected]>
- Loading branch information
Showing
6 changed files
with
187 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import axios from "axios"; | ||
|
||
export async function waitForWebApp(url: string | undefined, timeout = 30000) { | ||
if (!url) { | ||
throw new Error("URL is not defined"); | ||
} | ||
|
||
const startTime = Date.now(); | ||
while (true) { | ||
try { | ||
await axios.get(url); | ||
console.log(`Web application is ready: ${url}`); | ||
break; | ||
} catch (error) { | ||
console.log(`Web application is not ready: ${url}`); | ||
if (Date.now() - startTime > timeout) { | ||
throw new Error( | ||
`Web application not ready after ${timeout} ms: ${url}` | ||
); | ||
} | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
} | ||
} | ||
} |