Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

[AI Dev Tools Zoomcamp] Node.js test runner hangs when testing Socket.io and Express integration

Abierto Apto para principiantes
#397 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
85/100
Tipo de issue
Documentación
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
express, javascript, node.js

Línea de trabajo

Comienza revisando los cambios propuestos en el issue para server/index.js, tests/integration.test.js y package.json. Verifica que la guía documentada cubra el inicio protegido del servidor, la limpieza de Socket.io y del servidor HTTP, y el comando de pruebas; está listo cuando las FAQ expliquen claramente cómo evitar el bloqueo o el error ERR_SERVER_ALREADY_LISTEN.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Course & Homework
  • Course: AI Dev Tools Zoomcamp (2026)
  • Module: Homework 2 - Build and Ship an AI-Assisted Full-Stack App
Problem Description

When running integration tests for a collaborative full-stack application using Node.js's built-in test runner (node --test) against an Express and Socket.io server, the test process hangs indefinitely in the terminal after executing, or fails with ERR_SERVER_ALREADY_LISTEN.

Root Cause
  1. Premature port binding: If server.listen(PORT) is executed at the top level of server/index.js, importing the app/server into tests/integration.test.js causes the HTTP server to bind before the test hook can bind to an ephemeral port (0).
  2. Open handles: Socket.io and http.Server maintain persistent event loop connections and internal heartbeat timers, preventing Node's test runner from detecting an empty event loop.
Solution & Best Practice
  1. Guard server.listen in server/index.js:
    Ensure the server only listens when executed directly, not when imported by test suites:

    if (require.main === module) {
      server.listen(PORT, () => {
        console.log(`Server listening on port ${PORT}`);
      });
    }
    
  2. Explicitly close both io and server in the test cleanup hook:

    after(async () => {
      io.close();
      await new Promise((resolve) => serverInstance.close(resolve));
    });
    
  3. Use --test-force-exit in package.json:
    Add --test-force-exit so Node exits cleanly once all tests pass:

    "scripts": {
      "test": "node --test --test-force-exit tests/*.test.js"
    }
    
Lenguaje dominante
Python
Estrellas
7
Forks
19
Merge medio
3 d 20 h
PR fusionados (30 d)
9

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de DataTalksClub/faq

Todos los issues de DataTalksClub/faq

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.