Skip to content
Merged
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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"test:py": "npm --prefix packages/vovk-python run test",
"test:rs": "npm --prefix packages/vovk-rust run test",
"test": "npm run build && npm run test:main && npm run test:rs && npm run test:py && npm run test:cli",
"test-only": "npm run build && npm --prefix test run generate && cross-env PORT=3210 concurrently \"node scripts/wait-for-url.mjs http://localhost:3210/api/foo/client/common/nested-query && NODE_ENV=test node --experimental-strip-types --test --test-only --test-concurrency=1 ./test/**/*.test.ts\" \"npm run serve:unit\" --kill-others --success first",
"unit": "cross-env PORT=3210 concurrently \"npm run serve:unit\" \"node scripts/wait-for-url.mjs http://localhost:3210/api/foo/client/common/nested-query && npm run test:unit\" --kill-others --success first",
"unit:bun": "cross-env PORT=3210 concurrently \"npm run serve:unit:bun\" \"node scripts/wait-for-url.mjs http://localhost:3210/api/foo/client/common/nested-query && npm run test:unit\" --kill-others --success first",
"unit:deno": "cross-env PORT=3210 concurrently \"npm run serve:unit:deno\" \"node scripts/wait-for-url.mjs http://localhost:3210/api/foo/client/common/nested-query && npm run test:unit\" --kill-others --success first",
"test-only": "npm run build && npm --prefix test run generate && cross-env PORT=3210 concurrently \"node scripts/wait-for-test-app.mjs http://localhost:3210 && NODE_ENV=test node --experimental-strip-types --test --test-only --test-concurrency=1 ./test/**/*.test.ts\" \"npm run serve:unit\" --kill-others --success first",
"unit": "cross-env PORT=3210 concurrently \"npm run serve:unit\" \"node scripts/wait-for-test-app.mjs http://localhost:3210 && npm run test:unit\" --kill-others --success first",
"unit:bun": "cross-env PORT=3210 concurrently \"npm run serve:unit:bun\" \"node scripts/wait-for-test-app.mjs http://localhost:3210 && npm run test:unit\" --kill-others --success first",
"unit:deno": "cross-env PORT=3210 concurrently \"npm run serve:unit:deno\" \"node scripts/wait-for-test-app.mjs http://localhost:3210 && npm run test:unit\" --kill-others --success first",
"test:unit": "NODE_ENV=test node --experimental-strip-types --test --test-concurrency=1 ./test/**/*.test.ts",
"prettier": "prettier --write .",
"serve:unit": "npm --prefix test run generate && npm --prefix test run dev",
Expand Down
37 changes: 37 additions & 0 deletions scripts/wait-for-test-app.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Waits until the test app answers, then requests the schema of every segment one at a time.
// In `next dev` two compilations at once can read a half-written manifest and answer 500,
// so each segment is compiled here, before the tests and `vovk dev`'s own schema requests overlap.
// Usage: node scripts/wait-for-test-app.mjs <origin> [timeout seconds, 300 by default]
import { readdir } from 'node:fs/promises';
import path from 'node:path';

const [origin, timeoutSeconds = '300'] = process.argv.slice(2);
const deadline = Date.now() + Number(timeoutSeconds) * 1000;
const schemaDir = path.join(import.meta.dirname, '../test/.vovk-schema');

const segmentNames = (await readdir(schemaDir, { recursive: true }))
.filter((file) => file.endsWith('.json') && file !== '_meta.json')
.map((file) => file.slice(0, -'.json'.length).split(path.sep).join('/'))
.map((name) => (name === 'root' ? '' : name))
.sort();

async function waitFor(url) {
while (true) {
try {
const response = await fetch(url);
if (response.ok) return;
} catch {
// not listening yet
}
if (Date.now() > deadline) {
console.error(`${url} did not answer within ${timeoutSeconds}s`);
process.exit(1);
}
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}

await waitFor(`${origin}/api/foo/client/common/nested-query`);
for (const segmentName of segmentNames) {
await waitFor(`${origin}/api/${segmentName ? `${segmentName}/` : ''}_schema_`);
}
Loading