global-setup.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. const { execSync } = require('node:child_process');
  2. const COMPOSE_FILE = 'tests/docker-compose-playwright.yml';
  3. async function waitForReady(name, url, timeoutMs) {
  4. const start = Date.now();
  5. while (Date.now() - start < timeoutMs) {
  6. try {
  7. const response = await fetch(url, { redirect: 'manual' });
  8. if (response.ok) {
  9. return;
  10. }
  11. } catch {
  12. // Retry until timeout.
  13. }
  14. await new Promise((resolve) => setTimeout(resolve, 1000));
  15. }
  16. throw new Error(`Timed out waiting for ${name} at ${url}`);
  17. }
  18. module.exports = async () => {
  19. try {
  20. execSync(`docker compose -f ${COMPOSE_FILE} up -d --build`, {
  21. stdio: 'inherit',
  22. });
  23. } catch (error) {
  24. throw new Error(
  25. `Failed to start Docker test stack from ${COMPOSE_FILE}. ` +
  26. `Ensure Docker is running. Original error: ${error.message}`
  27. );
  28. }
  29. const timeoutMs = 180_000;
  30. await waitForReady('standalone', 'http://127.0.0.1:18180/index.html', timeoutMs);
  31. await waitForReady('standalone-new', 'http://127.0.0.1:18185/index.html', timeoutMs);
  32. await waitForReady('backend', 'http://127.0.0.1:18181/empty.php', timeoutMs);
  33. await waitForReady('frontend', 'http://127.0.0.1:18182/index-modern.html', timeoutMs);
  34. await waitForReady('dual', 'http://127.0.0.1:18183/index-modern.html', timeoutMs);
  35. };