custom-output.js
This file
Path
test/verbose/custom-output.js
129 lines · 6.7 KiB · JavaScript
Last changed by
TweaksSindre Sorhusbefore adoption698a1b8
History of this fileTake it
TweaksSindre Sorhusbefore adoption698a1b8
line 1why, one step back1import assert from 'node:assert/strict';Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 2why, one step back2import {inspect} from 'node:util';TweaksSindre Sorhusbefore adoption698a1b8
line 3why, one step back3import test from 'node:test';Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 4–16why, one step back4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {fullStdio} from '../helpers/stdio.js';6import {7 getNormalizedLine,8 getNormalizedLines,9 testTimestamp,10 runVerboseSubprocess,11} from '../helpers/verbose.js';12import {nestedSubprocess} from '../helpers/nested.js';13import {foobarObject} from '../helpers/input.js';1415setFixtureDirectory();16TweaksSindre Sorhusbefore adoption698a1b8
line 17why, one step back17const testPrintOutputCustom = async (fdNumber, isSync, hasOutput) => {Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 18–25why, one step back18 const {stderr} = await runVerboseSubprocess({19 optionsFixture: 'custom-print.js',20 isSync,21 type: 'output',22 fdNumber,23 });2425 if (hasOutput) {TweaksSindre Sorhusbefore adoption698a1b8
line 26why, one step back26 assert.equal(getNormalizedLine(stderr), `${testTimestamp} [0] . .`);Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 27why, one step back27 } else {TweaksSindre Sorhusbefore adoption698a1b8
line 28why, one step back28 assert.equal(stderr, '');Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 29–31why, one step back29 }30};31TweaksSindre Sorhusbefore adoption698a1b8
lines 32–41why, one step back32test('Prints stdout, verbose custom', () => testPrintOutputCustom(undefined, false, true));33test('Prints stdout, verbose custom, fd-specific stdout', () => testPrintOutputCustom('stdout', false, true));34test('Prints stdout, verbose custom, fd-specific stderr', () => testPrintOutputCustom('stderr', false, false));35test('Prints stdout, verbose custom, fd-specific fd3', () => testPrintOutputCustom('fd3', false, false));36test('Prints stdout, verbose custom, fd-specific ipc', () => testPrintOutputCustom('ipc', false, false));37test('Prints stdout, verbose custom, sync', () => testPrintOutputCustom(undefined, true, true));38test('Prints stdout, verbose custom, fd-specific stdout, sync', () => testPrintOutputCustom('stdout', true, true));39test('Prints stdout, verbose custom, fd-specific stderr, sync', () => testPrintOutputCustom('stderr', true, false));40test('Prints stdout, verbose custom, fd-specific fd3, sync', () => testPrintOutputCustom('fd3', true, false));41test('Prints stdout, verbose custom, fd-specific ipc, sync', () => testPrintOutputCustom('ipc', true, false));Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 42why, one step back42TweaksSindre Sorhusbefore adoption698a1b8
line 43why, one step back43const testPrintOutputOrder = async (fdNumber, secondFdNumber, hasOutput) => {Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 44–52why, one step back44 const {stderr} = await runVerboseSubprocess({45 optionsFixture: 'custom-print-multiple.js',46 type: 'output',47 fdNumber,48 secondFdNumber,49 ...fullStdio,50 });5152 if (hasOutput) {TweaksSindre Sorhusbefore adoption698a1b8
line 53why, one step back53 assert.equal(getNormalizedLine(stderr), `${testTimestamp} [0] . .`);Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 54why, one step back54 } else {TweaksSindre Sorhusbefore adoption698a1b8
line 55why, one step back55 assert.equal(stderr, '');Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 56–58why, one step back56 }57};58TweaksSindre Sorhusbefore adoption698a1b8
lines 59–70why, one step back59test('Prints stdout, verbose custom, fd-specific stdout+stderr', () => testPrintOutputOrder('stdout', 'stderr', true));60test('Prints stdout, verbose custom, fd-specific stderr+stdout', () => testPrintOutputOrder('stderr', 'stdout', false));61test('Prints stdout, verbose custom, fd-specific stdout+fd3', () => testPrintOutputOrder('stdout', 'fd3', true));62test('Prints stdout, verbose custom, fd-specific fd3+stdout', () => testPrintOutputOrder('fd3', 'stdout', false));63test('Prints stdout, verbose custom, fd-specific stdout+ipc', () => testPrintOutputOrder('stdout', 'ipc', true));64test('Prints stdout, verbose custom, fd-specific ipc+stdout', () => testPrintOutputOrder('ipc', 'stdout', false));65test('Prints stdout, verbose custom, fd-specific stderr+fd3', () => testPrintOutputOrder('stderr', 'fd3', false));66test('Prints stdout, verbose custom, fd-specific fd3+stderr', () => testPrintOutputOrder('fd3', 'stderr', false));67test('Prints stdout, verbose custom, fd-specific stderr+ipc', () => testPrintOutputOrder('stderr', 'ipc', false));68test('Prints stdout, verbose custom, fd-specific ipc+stderr', () => testPrintOutputOrder('ipc', 'stderr', false));69test('Prints stdout, verbose custom, fd-specific fd3+ipc', () => testPrintOutputOrder('fd3', 'ipc', false));70test('Prints stdout, verbose custom, fd-specific ipc+fd3', () => testPrintOutputOrder('ipc', 'fd3', false));Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 71why, one step back71TweaksSindre Sorhusbefore adoption698a1b8
line 72why, one step back72const testPrintOutputFunction = async (fdNumber, secondFdNumber, hasOutput) => {Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 73–81why, one step back73 const {stderr} = await runVerboseSubprocess({74 optionsFixture: 'custom-print-function.js',75 type: 'output',76 fdNumber,77 secondFdNumber,78 ...fullStdio,79 });8081 if (hasOutput) {TweaksSindre Sorhusbefore adoption698a1b8
line 82why, one step back82 assert.equal(getNormalizedLine(stderr), `${testTimestamp} [0] . .`);Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 83why, one step back83 } else {TweaksSindre Sorhusbefore adoption698a1b8
line 84why, one step back84 assert.equal(stderr, '');Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 85–87why, one step back85 }86};87TweaksSindre Sorhusbefore adoption698a1b8
lines 88–99why, one step back88test('Prints stdout, verbose custom, fd-specific stdout+stderr, single function', () => testPrintOutputFunction('stdout', 'stderr', true));89test('Prints stdout, verbose custom, fd-specific stderr+stdout, single function', () => testPrintOutputFunction('stderr', 'stdout', false));90test('Prints stdout, verbose custom, fd-specific stdout+fd3, single function', () => testPrintOutputFunction('stdout', 'fd3', true));91test('Prints stdout, verbose custom, fd-specific fd3+stdout, single function', () => testPrintOutputFunction('fd3', 'stdout', false));92test('Prints stdout, verbose custom, fd-specific stdout+ipc, single function', () => testPrintOutputFunction('stdout', 'ipc', true));93test('Prints stdout, verbose custom, fd-specific ipc+stdout, single function', () => testPrintOutputFunction('ipc', 'stdout', false));94test('Prints stdout, verbose custom, fd-specific stderr+fd3, single function', () => testPrintOutputFunction('stderr', 'fd3', false));95test('Prints stdout, verbose custom, fd-specific fd3+stderr, single function', () => testPrintOutputFunction('fd3', 'stderr', false));96test('Prints stdout, verbose custom, fd-specific stderr+ipc, single function', () => testPrintOutputFunction('stderr', 'ipc', false));97test('Prints stdout, verbose custom, fd-specific ipc+stderr, single function', () => testPrintOutputFunction('ipc', 'stderr', false));98test('Prints stdout, verbose custom, fd-specific fd3+ipc, single function', () => testPrintOutputFunction('fd3', 'ipc', false));99test('Prints stdout, verbose custom, fd-specific ipc+fd3, single function', () => testPrintOutputFunction('ipc', 'fd3', false));Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 100why, one step back100TweaksSindre Sorhusbefore adoption698a1b8
line 101why, one step back101const testVerboseMessage = async isSync => {Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 102–106why, one step back102 const {stderr} = await runVerboseSubprocess({103 isSync,104 type: 'output',105 eventProperty: 'message',106 });TweaksSindre Sorhusbefore adoption698a1b8
line 107why, one step back107 assert.equal(stderr, '. .');Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 108–109why, one step back108};109TweaksSindre Sorhusbefore adoption698a1b8
lines 110–111why, one step back110test('"verbose" function receives verboseObject.message', () => testVerboseMessage(false));111test('"verbose" function receives verboseObject.message, sync', () => testVerboseMessage(true));Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 112why, one step back112TweaksSindre Sorhusbefore adoption698a1b8
line 113why, one step back113const testPrintOutputMultiline = async isSync => {Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 114–119why, one step back114 const {stderr} = await runVerboseSubprocess({115 optionsFixture: 'custom-print.js',116 isSync,117 type: 'output',118 output: '.\n.',119 });TweaksSindre Sorhusbefore adoption698a1b8
line 120why, one step back120 assert.deepEqual(getNormalizedLines(stderr), [`${testTimestamp} [0] .`, `${testTimestamp} [0] .`]);Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 121–122why, one step back121};122TweaksSindre Sorhusbefore adoption698a1b8
lines 123–124why, one step back123test('"verbose" function receives verboseObject.message line-wise', () => testPrintOutputMultiline(false));124test('"verbose" function receives verboseObject.message line-wise, sync', () => testPrintOutputMultiline(true));Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 125why, one step back125TweaksSindre Sorhusbefore adoption698a1b8
line 126why, one step back126test('"verbose" function receives verboseObject.message serialized', async () => {Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 127why, one step back127 const {stderr} = await nestedSubprocess('noop.js', {optionsFixture: 'custom-object-stdout.js'});TweaksSindre Sorhusbefore adoption698a1b8
line 128why, one step back128 assert.equal(getNormalizedLine(stderr), `${testTimestamp} [0] ${inspect(foobarObject)}`);Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 129why, one step back129});