nodejs / nodejs/node

coverage testing blocked by promise should report where that promise came from

未关闭
#59,940 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

test_runner
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

Version

24.8.0

Platform
macos sequioa
Subsystem

test runner

What steps will reproduce the bug?

create any dir and put a test.js file in it with content:

import test, { describe } from "node:test";
import assert from "node:assert/strict";

describe(`project testing`, async () => {
  test(`this'll hang`, async () => {
    const value = await new Promise((resolve) => {
      console.log(`looks like this'll never resolve()`);
    });
    assert.equal(value, true);
  });
});

Then run this with node --test "test.js"

Obviously this'll never finish, so hit ctrl-c, which triggers the final report and shows:

^C✖ test.js (1376.646ms)
ℹ tests 1
ℹ suites 0
ℹ pass 0
ℹ fail 0
ℹ cancelled 1
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 1379.56475

✖ failing tests:

test at test.js:1:1
✖ test.js (1376.646ms)
  'Promise resolution is still pending but the event loop has already resolved'

And, sure: that's true... but this message also isn't information, because it tells us nothing that lets us fix the problem.

Which promise is still pending? Which file, line, and column and the promise invocation be found on? Because Node knows where promise call sites are, and it should include that information in the error report.

How often does it reproduce? Is there a required condition?

This is how things work right now.

What is the expected behavior? Why is that the expected behavior?

The error should be:

test at test.js:6:18
✖ test.js (1598.681125ms)
  'Promise resolution is still pending but the event loop has already resolved'

explicitly showing the line things went wrong on.

And if there is a promise pending because of some dependency of a dependency, it should show that entire trace: if test.js is awaiting getInfo() imported from ./utils.js and that calls getNetworkDeviceNames() imported from ./utils/network.js and that has a promise that never resolves, then this error should let folks find that problem:

test at test.js:6:18
  at utils.js:20:14
  at utils/network.js:112:25
✖ test.js (1598.681125ms)
  'Promise resolution is still pending but the event loop has already resolved'

Or however traces should be made to look for this functionality. The important part is that it's informative so that we can fix bugs. After all, that's the whole point of using node --test =)

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用所描述的 test.js 和 node --test "test.js" 重现该行为,然后从 test runner 对 pending-promise 报告的处理开始。跟踪 promise 调用点和依赖的异步调用是如何表示的,并定义输出,使其包含起始位置以及任何相关的依赖跟踪信息。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript
领域
testing
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
冷清
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。