Skip to content

Commit 1789e71

Browse files
authored
chore: improve local e2e setup (#1752)
2 parents 03bebee + cff6880 commit 1789e71

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

automation/run-e2e/lib/dev.mjs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,24 @@ export async function dev() {
6464
const url = process.env.URL ?? "http://127.0.0.1:8080";
6565

6666
console.log(c.cyan(`Make sure app is running on ${url}`));
67-
try {
68-
await await200(url);
69-
} catch {
70-
throw new Error(`Can't reach app on ${url}`);
67+
let appRunning = false;
68+
69+
while (!appRunning) {
70+
try {
71+
await await200(url);
72+
appRunning = true;
73+
} catch {
74+
const { retry } = await enquirer.prompt({
75+
type: "confirm",
76+
name: "retry",
77+
initial: true,
78+
message: `Can't reach app on ${url}. Do you want to retry?`
79+
});
80+
81+
if (!retry) {
82+
throw new Error(`App is not running on ${url}. Exiting.`);
83+
}
84+
}
7185
}
7286

7387
console.log(c.cyan("Launch Playwright"));

automation/run-e2e/lib/utils.mjs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,19 @@ export async function fetchGithubRestAPI(url, init = {}) {
3939

4040
export async function await200(url = "http://127.0.0.1:8080", attempts = 50) {
4141
let n = 0;
42-
while (++n <= attempts) {
43-
console.log(c.cyan(`GET ${url} ${n}`));
44-
const response = await fetch(url);
45-
const { ok, status } = response;
46-
47-
if (ok && status === 200) {
48-
console.log(c.green(`200 OK, continue`));
49-
return;
42+
while (n < attempts) {
43+
n++;
44+
console.log(c.cyan(`GET ${url} attempt ${n}/${attempts}`));
45+
try {
46+
const response = await fetch(url);
47+
const { ok, status } = response;
48+
49+
if (ok && status === 200) {
50+
console.log(c.green(`200 OK, continue`));
51+
return;
52+
}
53+
} catch (error) {
54+
console.error(c.red(`Error during fetch: ${error.message}`));
5055
}
5156

5257
await new Promise(resolve => setTimeout(resolve, 1000));

0 commit comments

Comments
 (0)