process.exit before console buffer flushed in Windows
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 38/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 停滯
- 技術堆疊
- javascript
- 領域
- cli, operating-systems, testing
研究方向
從 bin/nodeunit 的第 128-132 行附近開始,尤其是第 130 行的 process.exit(1),並在 Cygwin 下使用提供的 tests.js 重現此問題。確認失敗的執行會顯示所有主控台輸出,同時仍回傳結束代碼 1;現有的 workaround 提供了要驗證的預期行為。
由索引模型根據 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,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
caolan/nodeunit 的其他 Issue
-
難度 4/5 3-5 天 新手友好度 25/100
-
難度 3/5 1-2 天 新手友好度 35/100
-
難度 2/5 1-3 小時 新手友好度 42/100
-
難度 3/5 1-2 天 新手友好度 35/100
-
難度 5/5 一週以上 新手友好度 20/100
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
[BUG] npm pkg delete removes the first array item for a nonexistent property可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 83/100
維護者通常 2 天內回覆
-
feedback simulation workshop
難度 2/5 1-3 小時 新手友好度 72/100
githubnext/gh-aw-workshop#4755 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
videojs/video.js#9537 · 1 則留言 ·
維護者通常 1 天內回覆
-
fix
難度 1/5 1 小時以內 新手友好度 72/100
idean3885/claude-ops-agent#728 ·
維護者通常 1 天內回覆