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

process.exit before console buffer flushed in Windows

オープン
#282 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript

調査の方向性

bin/nodeunit の 128-132 行付近、特に 130 行目の process.exit(1) から始め、提供されている tests.js を Cygwin 上で使って問題を再現してください。失敗した実行でコンソール出力がすべて表示され、それでも終了コード 1 が返されることを確認してください。既存の回避策によって、検証すべき期待される動作が得られます。

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

説明

Symptoms

If any test fails, not all the console output is shown (console output is truncated).

Problem does not show up in standard Windows cmd, but does show up if tests are run from Cygwin or within Sublime Text build system. In Cygwin, if the output is piped to a file instead of being displayed on the console then all the results show in the file, even though they did not show in the console when not piped.

Environment

  • nodeunit 0.9.0,
  • node 0.10.17
  • Windows 7

Minimal Example

I have the following test file, tests.js:

for (var i = 0; i < 30; i++)
    console.log('' + i);

exports.dummy = function(test) {
    test.fail();
    test.done();
}

Running from Cygwin, the result is:

$ nodeunit tests.js
0

(I.e., only the first console.log appears). But if I remove the test.fail line then all the output appears.

Cause

My guess of the cause is given in the title. It appears that under different circumstances, sometimes the node console is asynchronous (perhaps due to the way Windows pipes work, I'm not sure), and doesn't flush the output after every write. When a test fails, line 130 in nodeunit/nodeunit process.exit(1); seems to recognize the error and exit the process, but process.exit does not seem to always wait for the console output to be received by the terminal. To confirm this hypothesis, if I remove the process.exit line, then the output is displayed correctly.

Solution

A work-around seems to be to change lines 128-132 to the following:

testrunner.run(files, options, function(err) {
    if (err) {
        process.on('exit', function() {
            process.exit(1);
        });
    }
});

This seems to produce the correct error code for the process and also show all the output. I don't know if there are any other side effects of not ending the process immediately in the callback function.

主要言語
JavaScript
スター
1.9k
フォーク
359
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

caolan/nodeunit のほかの issue

caolan/nodeunit の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

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

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