-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
30 additions
and
9 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
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 |
---|---|---|
@@ -1,35 +1,45 @@ | ||
/** | ||
* | ||
*/ | ||
|
||
export const TEST_URL = | ||
process.env.TEST_ENV ?? "http://localhost:3000/tefca-viewer"; | ||
|
||
/** | ||
* | ||
*/ | ||
async function globalSetup() { | ||
const url = "http://localhost:3000/tefca-viewer"; | ||
const maxRetries = 300; // Maximum number of retries | ||
const delay = 1000; // Delay between retries in milliseconds | ||
|
||
for (let attempts = 0; attempts < maxRetries; attempts++) { | ||
try { | ||
const response = await fetch(url); // Fetch the URL | ||
const response = await fetch(TEST_URL); // Fetch the TEST_URL | ||
if (response.status === 200) { | ||
console.log(`Connected to ${url} successfully.`); | ||
console.log(`Connected to ${TEST_URL} successfully.`); | ||
return; // Exit the function if the webpage loads successfully | ||
} else { | ||
console.log( | ||
`Failed to connect to ${url}, status: ${response.status}. Retrying...`, | ||
`Failed to connect to ${TEST_URL}, status: ${response.status}. Retrying...`, | ||
); | ||
// Wait before the next attempt | ||
await new Promise((resolve) => setTimeout(resolve, delay)); | ||
} | ||
} catch (error) { | ||
console.log( | ||
`Fetch failed for ${url}: ${(error as Error).message}. Retrying...`, | ||
`Fetch failed for ${TEST_URL}: ${ | ||
(error as Error).message | ||
}. Retrying...`, | ||
); | ||
await new Promise((resolve) => setTimeout(resolve, delay)); | ||
} | ||
// Wait before the next attempt | ||
await new Promise((resolve) => setTimeout(resolve, delay)); | ||
} | ||
|
||
throw new Error(`Unable to connect to ${url} after ${maxRetries} attempts.`); | ||
throw new Error( | ||
`Unable to connect to ${TEST_URL} after ${maxRetries} attempts.`, | ||
); | ||
} | ||
|
||
export default globalSetup; |
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