Skip to content
Myr

log.js

This file

Path

test/verbose/log.js

46 lines · 2.4 KiB · JavaScript

Last changed by

Fix the `verbose` option printing colors when `stderr` is not a terminalSindre Sorhusbefore adoptiona2eda67

History of this file

Take it

The walk stopped after 200 commits: lines older than 9f65b86 point at it.

TweaksSindre Sorhusbefore adoption698a1b8

line 1why, one step back
1import assert from 'node:assert/strict';

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 2why, one step back
2import {stripVTControlCharacters} from 'node:util';

TweaksSindre Sorhusbefore adoption698a1b8

line 3why, one step back
3import test from 'node:test';

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 4–5why, one step back
4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';
5import {foobarString} from '../helpers/input.js';

Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f

line 6why, one step back
6import {nestedSubprocess} from '../helpers/nested.js';

Do not write verbose logs synchronously (#1167)ehmickybefore adoptione3572d0

lines 7–8why, one step back
7import {getNormalizedLines, getCommandLine, getCompletionLine} from '../helpers/verbose.js';
8import {PARALLEL_COUNT} from '../helpers/parallel.js';

TweaksSindre Sorhusbefore adoption698a1b8

line 9why, one step back
9/* eslint-disable node-test/no-conditional-assertion -- shared helper functions are called from conditional paths on purpose */

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 10–12why, one step back
10
11setFixtureDirectory();12

TweaksSindre Sorhusbefore adoption698a1b8

line 13why, one step back
13const testNoStdout = async (verbose, isSync) => {

Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f

line 14why, one step back
14 const {stdout} = await nestedSubprocess('noop.js', [foobarString], {verbose, stdio: 'inherit', isSync});

TweaksSindre Sorhusbefore adoption698a1b8

line 15why, one step back
15 assert.equal(stdout, foobarString);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 16–17why, one step back
16};
17

TweaksSindre Sorhusbefore adoption698a1b8

lines 18–23why, one step back
18test('Logs on stderr not stdout, verbose "none"', () => testNoStdout('none', false));
19test('Logs on stderr not stdout, verbose "short"', () => testNoStdout('short', false));20test('Logs on stderr not stdout, verbose "full"', () => testNoStdout('full', false));21test('Logs on stderr not stdout, verbose "none", sync', () => testNoStdout('none', true));22test('Logs on stderr not stdout, verbose "short", sync', () => testNoStdout('short', true));23test('Logs on stderr not stdout, verbose "full", sync', () => testNoStdout('full', true));

100% test coverage (#1018)ehmickybefore adoption9f65b86

line 24why, one step back
24

Fix the `verbose` option printing colors when `stderr` is not a terminalSindre Sorhusbefore adoptiona2eda67

lines 25–26why, one step back
25const testColor = async (expectedResult, forceColor, term) => {
26 const {stderr} = await nestedSubprocess('noop.js', [foobarString], {verbose: 'short'}, {env: {FORCE_COLOR: forceColor, NO_COLOR: undefined, TERM: term}});

TweaksSindre Sorhusbefore adoption698a1b8

line 27why, one step back
27 assert.equal(stderr !== stripVTControlCharacters(stderr), expectedResult);

100% test coverage (#1018)ehmickybefore adoption9f65b86

lines 28–29why, one step back
28};
29

TweaksSindre Sorhusbefore adoption698a1b8

lines 30–31why, one step back
30test('Prints with colors if supported', () => testColor(true, '1'));
31test('Prints without colors if not supported', () => testColor(false, '0'));

Fix the `verbose` option printing colors when `stderr` is not a terminalSindre Sorhusbefore adoptiona2eda67

lines 32–33why, one step back
32// `stderr` is not a terminal, e.g. when redirected to a file, even though the terminal type supports colors
33test('Prints without colors if stderr is not a terminal', () => testColor(false, undefined, 'xterm-256color'));

Do not write verbose logs synchronously (#1167)ehmickybefore adoptione3572d0

line 34why, one step back
34

TweaksSindre Sorhusbefore adoption698a1b8

line 35why, one step back
35test('Prints lines in order when interleaved with subprocess stderr', async () => {

Do not write verbose logs synchronously (#1167)ehmickybefore adoptione3572d0

line 36why, one step back
36 const results = await Promise.all(Array.from({length: PARALLEL_COUNT}, () =>

Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454

line 37why, one step back
37 nestedSubprocess('noop-fd.js', ['2', `${foobarString}\n`], {verbose: 'full', stderr: 'inherit'}, {all: true})));

Do not write verbose logs synchronously (#1167)ehmickybefore adoptione3572d0

line 38why, one step back
38 for (const {all} of results) {

TweaksSindre Sorhusbefore adoption698a1b8

line 39why, one step back
39 assert.deepEqual(

Do not write verbose logs synchronously (#1167)ehmickybefore adoptione3572d0

lines 40–44why, one step back
40 getNormalizedLines(all),
41 [getCommandLine(all), foobarString, getCompletionLine(all)],42 );43 }44});

TweaksSindre Sorhusbefore adoption698a1b8

lines 45–46why, one step back
45
46/* eslint-enable node-test/no-conditional-assertion */