Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

クローズ 初心者向け
#397 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
85/100
issue の種類
ドキュメント
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
express, javascript, node.js

調査の方向性

まず、server/index.js、tests/integration.test.js、package.json に対して issue で提案されている変更を確認します。文書化されたガイダンスが、サーバーのガード付き起動、Socket.io と HTTP サーバーのクリーンアップ、テストコマンドを網羅していることを検証します。FAQ でハングまたは ERR_SERVER_ALREADY_LISTEN エラーを防ぐ方法が明確に説明されていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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"
    }
    
主要言語
Python
スター
7
フォーク
19
平均マージ
9日 22時間
マージ済み PR(30日)
10

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

DataTalksClub/faq のほかの issue

DataTalksClub/faq の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。