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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130import assert from 'node:assert/strict';import {inspect} from 'node:util';import test from 'node:test';import {setFixtureDirectory} from '../helpers/fixtures-directory.js';import {fullStdio} from '../helpers/stdio.js';import { getNormalizedLine, getNormalizedLines, testTimestamp, runVerboseSubprocess,} from '../helpers/verbose.js';import {nestedSubprocess} from '../helpers/nested.js';import {foobarObject} from '../helpers/input.js';
setFixtureDirectory();
const testPrintOutputCustom = async (fdNumber, isSync, hasOutput) => { const {stderr} = await runVerboseSubprocess({ optionsFixture: 'custom-print.js', isSync, type: 'output', fdNumber, });
if (hasOutput) { assert.equal(getNormalizedLine(stderr), `${testTimestamp} [0] . .`); } else { assert.equal(stderr, ''); }};
test('Prints stdout, verbose custom', () => testPrintOutputCustom(undefined, false, true));test('Prints stdout, verbose custom, fd-specific stdout', () => testPrintOutputCustom('stdout', false, true));test('Prints stdout, verbose custom, fd-specific stderr', () => testPrintOutputCustom('stderr', false, false));test('Prints stdout, verbose custom, fd-specific fd3', () => testPrintOutputCustom('fd3', false, false));test('Prints stdout, verbose custom, fd-specific ipc', () => testPrintOutputCustom('ipc', false, false));test('Prints stdout, verbose custom, sync', () => testPrintOutputCustom(undefined, true, true));test('Prints stdout, verbose custom, fd-specific stdout, sync', () => testPrintOutputCustom('stdout', true, true));test('Prints stdout, verbose custom, fd-specific stderr, sync', () => testPrintOutputCustom('stderr', true, false));test('Prints stdout, verbose custom, fd-specific fd3, sync', () => testPrintOutputCustom('fd3', true, false));test('Prints stdout, verbose custom, fd-specific ipc, sync', () => testPrintOutputCustom('ipc', true, false));
const testPrintOutputOrder = async (fdNumber, secondFdNumber, hasOutput) => { const {stderr} = await runVerboseSubprocess({ optionsFixture: 'custom-print-multiple.js', type: 'output', fdNumber, secondFdNumber, ...fullStdio, });
if (hasOutput) { assert.equal(getNormalizedLine(stderr), `${testTimestamp} [0] . .`); } else { assert.equal(stderr, ''); }};
test('Prints stdout, verbose custom, fd-specific stdout+stderr', () => testPrintOutputOrder('stdout', 'stderr', true));test('Prints stdout, verbose custom, fd-specific stderr+stdout', () => testPrintOutputOrder('stderr', 'stdout', false));test('Prints stdout, verbose custom, fd-specific stdout+fd3', () => testPrintOutputOrder('stdout', 'fd3', true));test('Prints stdout, verbose custom, fd-specific fd3+stdout', () => testPrintOutputOrder('fd3', 'stdout', false));test('Prints stdout, verbose custom, fd-specific stdout+ipc', () => testPrintOutputOrder('stdout', 'ipc', true));test('Prints stdout, verbose custom, fd-specific ipc+stdout', () => testPrintOutputOrder('ipc', 'stdout', false));test('Prints stdout, verbose custom, fd-specific stderr+fd3', () => testPrintOutputOrder('stderr', 'fd3', false));test('Prints stdout, verbose custom, fd-specific fd3+stderr', () => testPrintOutputOrder('fd3', 'stderr', false));test('Prints stdout, verbose custom, fd-specific stderr+ipc', () => testPrintOutputOrder('stderr', 'ipc', false));test('Prints stdout, verbose custom, fd-specific ipc+stderr', () => testPrintOutputOrder('ipc', 'stderr', false));test('Prints stdout, verbose custom, fd-specific fd3+ipc', () => testPrintOutputOrder('fd3', 'ipc', false));test('Prints stdout, verbose custom, fd-specific ipc+fd3', () => testPrintOutputOrder('ipc', 'fd3', false));
const testPrintOutputFunction = async (fdNumber, secondFdNumber, hasOutput) => { const {stderr} = await runVerboseSubprocess({ optionsFixture: 'custom-print-function.js', type: 'output', fdNumber, secondFdNumber, ...fullStdio, });
if (hasOutput) { assert.equal(getNormalizedLine(stderr), `${testTimestamp} [0] . .`); } else { assert.equal(stderr, ''); }};
test('Prints stdout, verbose custom, fd-specific stdout+stderr, single function', () => testPrintOutputFunction('stdout', 'stderr', true));test('Prints stdout, verbose custom, fd-specific stderr+stdout, single function', () => testPrintOutputFunction('stderr', 'stdout', false));test('Prints stdout, verbose custom, fd-specific stdout+fd3, single function', () => testPrintOutputFunction('stdout', 'fd3', true));test('Prints stdout, verbose custom, fd-specific fd3+stdout, single function', () => testPrintOutputFunction('fd3', 'stdout', false));test('Prints stdout, verbose custom, fd-specific stdout+ipc, single function', () => testPrintOutputFunction('stdout', 'ipc', true));test('Prints stdout, verbose custom, fd-specific ipc+stdout, single function', () => testPrintOutputFunction('ipc', 'stdout', false));test('Prints stdout, verbose custom, fd-specific stderr+fd3, single function', () => testPrintOutputFunction('stderr', 'fd3', false));test('Prints stdout, verbose custom, fd-specific fd3+stderr, single function', () => testPrintOutputFunction('fd3', 'stderr', false));test('Prints stdout, verbose custom, fd-specific stderr+ipc, single function', () => testPrintOutputFunction('stderr', 'ipc', false));test('Prints stdout, verbose custom, fd-specific ipc+stderr, single function', () => testPrintOutputFunction('ipc', 'stderr', false));test('Prints stdout, verbose custom, fd-specific fd3+ipc, single function', () => testPrintOutputFunction('fd3', 'ipc', false));test('Prints stdout, verbose custom, fd-specific ipc+fd3, single function', () => testPrintOutputFunction('ipc', 'fd3', false));
const testVerboseMessage = async isSync => { const {stderr} = await runVerboseSubprocess({ isSync, type: 'output', eventProperty: 'message', }); assert.equal(stderr, '. .');};
test('"verbose" function receives verboseObject.message', () => testVerboseMessage(false));test('"verbose" function receives verboseObject.message, sync', () => testVerboseMessage(true));
const testPrintOutputMultiline = async isSync => { const {stderr} = await runVerboseSubprocess({ optionsFixture: 'custom-print.js', isSync, type: 'output', output: '.\n.', }); assert.deepEqual(getNormalizedLines(stderr), [`${testTimestamp} [0] .`, `${testTimestamp} [0] .`]);};
test('"verbose" function receives verboseObject.message line-wise', () => testPrintOutputMultiline(false));test('"verbose" function receives verboseObject.message line-wise, sync', () => testPrintOutputMultiline(true));
test('"verbose" function receives verboseObject.message serialized', async () => { const {stderr} = await nestedSubprocess('noop.js', {optionsFixture: 'custom-object-stdout.js'}); assert.equal(getNormalizedLine(stderr), `${testTimestamp} [0] ${inspect(foobarObject)}`);});