Skip to content

Commit 51b4202

Browse files
feat(test): wait until server is ready
Signed-off-by: Victor Adossi <vadossi@cosmonic.com>
1 parent 55175be commit 51b4202

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/builtins/fetch.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ export async function test(run, testState) {
4949
res.end();
5050
}).listen(port);
5151

52+
// Wait until the server is ready
53+
let ready = false;
54+
const url = FETCH_URL + (port ? ':' + port : '');
55+
while (!ready) {
56+
try {
57+
const res = await fetch(url);
58+
ready = true;
59+
} catch (err) {
60+
await new Promise((resolve) => setTimeout(resolve, 250));
61+
}
62+
}
63+
5264
const { stdout, stderr } = await run();
5365
strictEqual(stderr, '');
5466
strictEqual(stdout.trim(), FETCH_URL);

0 commit comments

Comments
 (0)