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 fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
TweaksSindre Sorhusbefore adoption698a1b8
line 1why, one step back1import assert from 'node:assert/strict';100% test coverage (#1018)ehmickybefore adoption9f65b86
line 2why, one step back2import {stripVTControlCharacters} from 'node:util';TweaksSindre Sorhusbefore adoption698a1b8
line 3why, one step back3import test from 'node:test';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 4–5why, one step back4import {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 back6import {nestedSubprocess} from '../helpers/nested.js';Do not write verbose logs synchronously (#1167)ehmickybefore adoptione3572d0
lines 7–8why, one step back7import {getNormalizedLines, getCommandLine, getCompletionLine} from '../helpers/verbose.js';8import {PARALLEL_COUNT} from '../helpers/parallel.js';TweaksSindre Sorhusbefore adoption698a1b8
line 9why, one step back9/* 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 back1011setFixtureDirectory();12TweaksSindre Sorhusbefore adoption698a1b8
line 13why, one step back13const testNoStdout = async (verbose, isSync) => {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 14why, one step back14 const {stdout} = await nestedSubprocess('noop.js', [foobarString], {verbose, stdio: 'inherit', isSync});TweaksSindre Sorhusbefore adoption698a1b8
line 15why, one step back15 assert.equal(stdout, foobarString);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 16–17why, one step back16};17TweaksSindre Sorhusbefore adoption698a1b8
lines 18–23why, one step back18test('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 back24Fix the `verbose` option printing colors when `stderr` is not a terminalSindre Sorhusbefore adoptiona2eda67
lines 25–26why, one step back25const 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 back27 assert.equal(stderr !== stripVTControlCharacters(stderr), expectedResult);100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 28–29why, one step back28};29TweaksSindre Sorhusbefore adoption698a1b8
lines 30–31why, one step back30test('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 back32// `stderr` is not a terminal, e.g. when redirected to a file, even though the terminal type supports colors33test('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 back34TweaksSindre Sorhusbefore adoption698a1b8
line 35why, one step back35test('Prints lines in order when interleaved with subprocess stderr', async () => {Do not write verbose logs synchronously (#1167)ehmickybefore adoptione3572d0
line 36why, one step back36 const results = await Promise.all(Array.from({length: PARALLEL_COUNT}, () =>Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454
line 37why, one step back37 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 back38 for (const {all} of results) {TweaksSindre Sorhusbefore adoption698a1b8
line 39why, one step back39 assert.deepEqual(Do not write verbose logs synchronously (#1167)ehmickybefore adoptione3572d0
lines 40–44why, one step back40 getNormalizedLines(all),41 [getCommandLine(all), foobarString, getCompletionLine(all)],42 );43 }44});TweaksSindre Sorhusbefore adoption698a1b8
lines 45–46why, one step back4546/* eslint-enable node-test/no-conditional-assertion */