nodejs / nodejs/node

`styleText()`: isTTY check fails with `--test`

未关闭
#57,921 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

test_runner
主要语言
JavaScript
星标
122k
派生
37.3k
平均合并
4 天 2 小时
30 天内合并 PR
283

描述

Version

v22.13.1

Platform
Linux 6.8.0-57-generic #59~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Wed Mar 19 17:07:41 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
Subsystem

Ubuntu 22.04.5 LTS

What steps will reproduce the bug?
  • Create index.mjs:

    import { Writable } from "node:stream";
    import { styleText } from "node:util";
    
    const streamTTY = new class extends Writable {
        isTTY = true;
    };
    const streamNoTTY = new class extends Writable {
        isTTY = false;
    };
    
    console.log(styleText("bgYellow", "TTY", { stream: streamTTY }));
    console.log(styleText("bgYellow", "No TTY", { stream: streamNoTTY }));
    
  • Run node index.mjs

  • Run node --test index.mjs

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

Always.

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

The text No TTY isn't stylized with --test.

  • node index.mjs

    ^[[43mTTY^[[49m
    No TTY
    
  • node --test index.mjs

    ^[[43mTTY^[[49m
    No TTY
    ✔ index.mjs (27.022452ms)
    ...
    
What do you see instead?

The text No TTY is stylized with --test.

  • node index.mjs

    ^[[43mTTY^[[49m
    No TTY
    
  • node --test index.mjs

    ^[[43mTTY^[[49m
    ^[[43mNo TTY^[[49m
    ✔ index.mjs (27.022452ms)
    ...
    
Additional information

With the --test option, the styleText() function doesn't check whether the stream is TTY.


With the command line: node --test index.mjs > out.txt, the file contains the correct style:

TAP version 13
# ^[[43mTTY^[[49m
# No TTY
# Subtest: index.mjs
ok 1 - index.mjs
  ---
  duration_ms: 25.169793
  ...
1..1
# tests 1
# suites 0
# pass 1
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms 30.191704

贡献指南

打开贡献指南

从这里开始

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

调研方向

从 index.mjs 中的复现开始,分别使用 node index.mjsnode --test index.mjs 运行,并比较 TTY 和 non-TTY 输出。在测试运行器处于活动状态时,跟踪 styleText() 对所提供 stream 的处理。完成标准是:在 --test 下 non-TTY stream 仍保持无样式,同时 TTY 样式和重定向输出保持当前行为。

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

评估

技术栈
javascript, node.js
领域
testing-qa
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
62/100

把新 issue 发到你的邮箱

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