nodejs / nodejs/node

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

Đang mở
#57,921 5 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

test_runner
Ngôn ngữ chính
JavaScript
Star
122k
Fork
37.4k
Merge trung bình
4 ngày 3 giờ
Pull request đã merge (30 ngày)
272

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với bản tái hiện trong index.mjs và chạy nó bằng cả node index.mjs lẫn node --test index.mjs, đồng thời so sánh đầu ra TTY và non-TTY. Theo dõi cách styleText() xử lý stream được cung cấp khi test runner đang hoạt động. Hoàn tất khi stream non-TTY vẫn không có kiểu định dạng dưới --test, trong khi việc tạo kiểu TTY và đầu ra được chuyển hướng vẫn giữ nguyên hành vi hiện tại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, node.js
Lĩnh vực
testing-qa
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
62/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.