Skip to content

Commit 955f21f

Browse files
committed
fix(create-blocks-app): decouple E2E readiness from sample API
1 parent 348d934 commit 955f21f

5 files changed

Lines changed: 35 additions & 13 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-blocks/create-blocks-app': patch
3+
---
4+
5+
Make starter template E2E setup wait for the Blocks server without depending on a sample API.

packages/create-blocks-app/templates/auth-cognito/test/e2e.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ test.before(async () => {
2727
api = mod.api;
2828
hello = mod.hello;
2929

30-
// Wait for server to be ready
30+
// Wait for the Blocks server to be ready without depending on the sample API.
3131
for (let i = 0; i < 60; i++) {
32-
try { await hello.greet('ping'); return; } catch {
33-
await setTimeout(1000);
32+
try {
33+
const response = await fetch('http://localhost:3000/.blocks-sandbox/config.json');
34+
if (response.ok) return;
35+
} catch {
36+
// The server is not listening yet.
3437
}
38+
await setTimeout(1000);
3539
}
3640
throw new Error('Server not ready');
3741
});

packages/create-blocks-app/templates/backend/test/e2e.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ installCookieJar();
99

1010
let server: ChildProcess | null = null;
1111
let api: typeof apiType;
12+
const serverPort = 3001;
1213

1314
test.before(async () => {
14-
if (!await isServerRunning()) {
15+
if (!await isServerRunning(serverPort)) {
1516
server = spawn('npm', ['run', 'dev'], {
1617
cwd: process.cwd(),
1718
stdio: ['ignore', 'pipe', 'pipe'],
@@ -25,11 +26,15 @@ test.before(async () => {
2526
const mod = await import('aws-blocks');
2627
api = mod.api;
2728

28-
// Wait for server to be ready
29+
// Wait for the Blocks server to be ready without depending on the sample API.
2930
for (let i = 0; i < 30; i++) {
30-
try { await api.greet('ping'); return; } catch {
31-
await setTimeout(1000);
31+
try {
32+
const response = await fetch(`http://localhost:${serverPort}/.blocks-sandbox/config.json`);
33+
if (response.ok) return;
34+
} catch {
35+
// The server is not listening yet.
3236
}
37+
await setTimeout(1000);
3338
}
3439
throw new Error('Server not ready');
3540
});

packages/create-blocks-app/templates/bare/test/e2e.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ test.before(async () => {
2525
const mod = await import('aws-blocks');
2626
api = mod.api;
2727

28-
// Wait for server to be ready
28+
// Wait for the Blocks server to be ready without depending on the sample API.
2929
for (let i = 0; i < 30; i++) {
30-
try { await api.greet('ping'); return; } catch {
31-
await setTimeout(1000);
30+
try {
31+
const response = await fetch('http://localhost:3000/.blocks-sandbox/config.json');
32+
if (response.ok) return;
33+
} catch {
34+
// The server is not listening yet.
3235
}
36+
await setTimeout(1000);
3337
}
3438
throw new Error('Server not ready');
3539
});

packages/create-blocks-app/templates/demo/test/e2e.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ test.before(async () => {
2727
api = mod.api;
2828
hello = mod.hello;
2929

30-
// Wait for server to be ready
30+
// Wait for the Blocks server to be ready without depending on the sample API.
3131
for (let i = 0; i < 60; i++) {
32-
try { await hello.greet('ping'); return; } catch {
33-
await setTimeout(1000);
32+
try {
33+
const response = await fetch('http://localhost:3000/.blocks-sandbox/config.json');
34+
if (response.ok) return;
35+
} catch {
36+
// The server is not listening yet.
3437
}
38+
await setTimeout(1000);
3539
}
3640
throw new Error('Server not ready');
3741
});

0 commit comments

Comments
 (0)