Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tidy-template-readiness.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-blocks/create-blocks-app': patch
---

Make starter template E2E setup wait for the Blocks server without depending on a sample API.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ test.before(async () => {
api = mod.api;
hello = mod.hello;

// Wait for server to be ready
// Wait for the Blocks server to be ready without depending on the sample API.
for (let i = 0; i < 60; i++) {
try { await hello.greet('ping'); return; } catch {
await setTimeout(1000);
try {
const response = await fetch('http://localhost:3000/.blocks-sandbox/config.json');
if (response.ok) return;
} catch {
// The server is not listening yet.
}
await setTimeout(1000);
}
throw new Error('Server not ready');
});
Expand Down
13 changes: 9 additions & 4 deletions packages/create-blocks-app/templates/backend/test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ installCookieJar();

let server: ChildProcess | null = null;
let api: typeof apiType;
const serverPort = 3001;

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

// Wait for server to be ready
// Wait for the Blocks server to be ready without depending on the sample API.
for (let i = 0; i < 30; i++) {
try { await api.greet('ping'); return; } catch {
await setTimeout(1000);
try {
const response = await fetch(`http://localhost:${serverPort}/.blocks-sandbox/config.json`);
if (response.ok) return;
} catch {
// The server is not listening yet.
}
await setTimeout(1000);
}
throw new Error('Server not ready');
});
Expand Down
10 changes: 7 additions & 3 deletions packages/create-blocks-app/templates/bare/test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@ test.before(async () => {
const mod = await import('aws-blocks');
api = mod.api;

// Wait for server to be ready
// Wait for the Blocks server to be ready without depending on the sample API.
for (let i = 0; i < 30; i++) {
try { await api.greet('ping'); return; } catch {
await setTimeout(1000);
try {
const response = await fetch('http://localhost:3000/.blocks-sandbox/config.json');
if (response.ok) return;
} catch {
// The server is not listening yet.
}
await setTimeout(1000);
}
throw new Error('Server not ready');
});
Expand Down
10 changes: 7 additions & 3 deletions packages/create-blocks-app/templates/demo/test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ test.before(async () => {
api = mod.api;
hello = mod.hello;

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