intellitester 0.2.43 → 0.2.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1214,14 +1214,6 @@ async function isServerRunning(url) {
1214
1214
  return false;
1215
1215
  }
1216
1216
  }
1217
- async function waitForServer(url, timeout) {
1218
- const start = Date.now();
1219
- while (Date.now() - start < timeout) {
1220
- if (await isServerRunning(url)) return;
1221
- await new Promise((r) => setTimeout(r, 500));
1222
- }
1223
- throw new Error(`Server at ${url} not ready after ${timeout}ms`);
1224
- }
1225
1217
  async function detectBuildDirectory(cwd) {
1226
1218
  const commonDirs = [
1227
1219
  ".next",
@@ -1334,7 +1326,7 @@ async function detectServerCommand(cwd) {
1334
1326
  throw new Error("Could not auto-detect server command. Please specify command explicitly.");
1335
1327
  }
1336
1328
  async function startWebServer(config) {
1337
- const { url, reuseExistingServer = true, timeout = 3e4 } = config;
1329
+ const { url, reuseExistingServer = true, timeout = 3e4, idleTimeout = 2e4 } = config;
1338
1330
  const cwd = config.workdir ?? config.cwd ?? process.cwd();
1339
1331
  if (reuseExistingServer && await isServerRunning(url)) {
1340
1332
  console.log(`Server already running at ${url}`);
@@ -1358,13 +1350,58 @@ async function startWebServer(config) {
1358
1350
  cwd,
1359
1351
  detached: false
1360
1352
  });
1353
+ let stderrOutput = "";
1354
+ let lastOutputTime = Date.now();
1361
1355
  serverProcess.stdout?.on("data", (data) => {
1356
+ lastOutputTime = Date.now();
1362
1357
  process.stdout.write(`[server] ${data}`);
1363
1358
  });
1364
1359
  serverProcess.stderr?.on("data", (data) => {
1360
+ lastOutputTime = Date.now();
1361
+ stderrOutput += data.toString();
1365
1362
  process.stderr.write(`[server] ${data}`);
1366
1363
  });
1367
- await waitForServer(url, timeout);
1364
+ await new Promise((resolve, reject) => {
1365
+ let resolved = false;
1366
+ const startTime = Date.now();
1367
+ const cleanup = () => {
1368
+ resolved = true;
1369
+ clearInterval(pollInterval);
1370
+ };
1371
+ serverProcess.on("close", (code) => {
1372
+ if (!resolved && code !== 0 && code !== null) {
1373
+ cleanup();
1374
+ reject(new Error(`Server exited with code ${code}
1375
+ ${stderrOutput}`));
1376
+ }
1377
+ });
1378
+ serverProcess.on("error", (err) => {
1379
+ if (!resolved) {
1380
+ cleanup();
1381
+ reject(err);
1382
+ }
1383
+ });
1384
+ const pollInterval = setInterval(async () => {
1385
+ if (resolved) return;
1386
+ if (await isServerRunning(url)) {
1387
+ cleanup();
1388
+ resolve();
1389
+ return;
1390
+ }
1391
+ if (Date.now() - startTime > timeout) {
1392
+ cleanup();
1393
+ reject(new Error(`Server at ${url} not ready after ${timeout}ms`));
1394
+ return;
1395
+ }
1396
+ if (Date.now() - lastOutputTime > idleTimeout) {
1397
+ cleanup();
1398
+ serverProcess.kill("SIGTERM");
1399
+ reject(new Error(`Server stalled - no output for ${idleTimeout}ms. Last output:
1400
+ ${stderrOutput.slice(-500)}`));
1401
+ return;
1402
+ }
1403
+ }, 500);
1404
+ });
1368
1405
  console.log(`Server ready at ${url}`);
1369
1406
  return serverProcess;
1370
1407
  }
@@ -3394,5 +3431,5 @@ exports.runWorkflowWithContext = runWorkflowWithContext;
3394
3431
  exports.setupAppwriteTracking = setupAppwriteTracking;
3395
3432
  exports.startTrackingServer = startTrackingServer;
3396
3433
  exports.startWebServer = startWebServer;
3397
- //# sourceMappingURL=chunk-GDPJLAXU.cjs.map
3398
- //# sourceMappingURL=chunk-GDPJLAXU.cjs.map
3434
+ //# sourceMappingURL=chunk-C46Q6B6I.cjs.map
3435
+ //# sourceMappingURL=chunk-C46Q6B6I.cjs.map