nodejs / nodejs/node

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

Aperta
#57,921 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

test_runner
Lingua principale
JavaScript
Stelle
122k
Fork
37.3k
Merge medio
4g 2h
PR unite (30g)
283

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la riproduzione in index.mjs ed eseguila sia con node index.mjs sia con node --test index.mjs, confrontando l'output TTY e non-TTY. Traccia la gestione dello stream fornito da styleText() mentre il test runner è attivo. Il lavoro è completato quando lo stream non-TTY rimane senza stili con --test, mentre lo stile TTY e l'output reindirizzato mantengono il comportamento attuale.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, node.js
Ambito
testing-qa
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
62/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.