Skip to content
Myr

custom-ipc.js

This file

Path

test/verbose/custom-ipc.js

120 lines · 5.6 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

TweaksSindre Sorhusbefore adoption698a1b8

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

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

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

TweaksSindre Sorhusbefore adoption698a1b8

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

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 4–16why, one step back
4import {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();16

TweaksSindre Sorhusbefore adoption698a1b8

line 17why, one step back
17const testPrintIpcCustom = async (fdNumber, hasOutput) => {

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 18–25why, one step back
18 const {stderr} = await runVerboseSubprocess({
19 optionsFixture: 'custom-print.js',20 type: 'ipc',21 fdNumber,22 ...fullStdio,23 });2425 if (hasOutput) {

TweaksSindre Sorhusbefore adoption698a1b8

line 26why, one step back
26 assert.equal(getNormalizedLine(stderr), `${testTimestamp} [0] * . .`);

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

line 27why, one step back
27 } else {

TweaksSindre Sorhusbefore adoption698a1b8

line 28why, one step back
28 assert.equal(stderr, '');

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 29–31why, one step back
29 }
30};31

TweaksSindre Sorhusbefore adoption698a1b8

lines 32–36why, one step back
32test('Prints IPC, verbose custom', () => testPrintIpcCustom(undefined, true));
33test('Prints IPC, verbose custom, fd-specific stdout', () => testPrintIpcCustom('stdout', false));34test('Prints IPC, verbose custom, fd-specific stderr', () => testPrintIpcCustom('stderr', false));35test('Prints IPC, verbose custom, fd-specific fd3', () => testPrintIpcCustom('fd3', false));36test('Prints IPC, verbose custom, fd-specific ipc', () => testPrintIpcCustom('ipc', true));

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

line 37why, one step back
37

TweaksSindre Sorhusbefore adoption698a1b8

line 38why, one step back
38const testPrintIpcOrder = async (fdNumber, secondFdNumber, hasOutput) => {

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 39–47why, one step back
39 const {stderr} = await runVerboseSubprocess({
40 optionsFixture: 'custom-print-multiple.js',41 type: 'ipc',42 fdNumber,43 secondFdNumber,44 ...fullStdio,45 });4647 if (hasOutput) {

TweaksSindre Sorhusbefore adoption698a1b8

line 48why, one step back
48 assert.equal(getNormalizedLine(stderr), `${testTimestamp} [0] * . .`);

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

line 49why, one step back
49 } else {

TweaksSindre Sorhusbefore adoption698a1b8

line 50why, one step back
50 assert.equal(stderr, '');

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 51–53why, one step back
51 }
52};53

TweaksSindre Sorhusbefore adoption698a1b8

lines 54–65why, one step back
54test('Prints IPC, verbose custom, fd-specific stdout+stderr', () => testPrintIpcOrder('stdout', 'stderr', false));
55test('Prints IPC, verbose custom, fd-specific stderr+stdout', () => testPrintIpcOrder('stderr', 'stdout', false));56test('Prints IPC, verbose custom, fd-specific stdout+fd3', () => testPrintIpcOrder('stdout', 'fd3', false));57test('Prints IPC, verbose custom, fd-specific fd3+stdout', () => testPrintIpcOrder('fd3', 'stdout', false));58test('Prints IPC, verbose custom, fd-specific stdout+ipc', () => testPrintIpcOrder('stdout', 'ipc', false));59test('Prints IPC, verbose custom, fd-specific ipc+stdout', () => testPrintIpcOrder('ipc', 'stdout', true));60test('Prints IPC, verbose custom, fd-specific stderr+fd3', () => testPrintIpcOrder('stderr', 'fd3', false));61test('Prints IPC, verbose custom, fd-specific fd3+stderr', () => testPrintIpcOrder('fd3', 'stderr', false));62test('Prints IPC, verbose custom, fd-specific stderr+ipc', () => testPrintIpcOrder('stderr', 'ipc', false));63test('Prints IPC, verbose custom, fd-specific ipc+stderr', () => testPrintIpcOrder('ipc', 'stderr', true));64test('Prints IPC, verbose custom, fd-specific fd3+ipc', () => testPrintIpcOrder('fd3', 'ipc', false));65test('Prints IPC, verbose custom, fd-specific ipc+fd3', () => testPrintIpcOrder('ipc', 'fd3', true));

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

line 66why, one step back
66

TweaksSindre Sorhusbefore adoption698a1b8

line 67why, one step back
67const testPrintIpcFunction = async (fdNumber, secondFdNumber, hasOutput) => {

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 68–76why, one step back
68 const {stderr} = await runVerboseSubprocess({
69 optionsFixture: 'custom-print-function.js',70 type: 'ipc',71 fdNumber,72 secondFdNumber,73 ...fullStdio,74 });7576 if (hasOutput) {

TweaksSindre Sorhusbefore adoption698a1b8

line 77why, one step back
77 assert.equal(getNormalizedLine(stderr), `${testTimestamp} [0] * . .`);

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

line 78why, one step back
78 } else {

TweaksSindre Sorhusbefore adoption698a1b8

line 79why, one step back
79 assert.equal(stderr, '');

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 80–82why, one step back
80 }
81};82

TweaksSindre Sorhusbefore adoption698a1b8

lines 83–94why, one step back
83test('Prints IPC, verbose custom, fd-specific stdout+stderr, single function', () => testPrintIpcFunction('stdout', 'stderr', false));
84test('Prints IPC, verbose custom, fd-specific stderr+stdout, single function', () => testPrintIpcFunction('stderr', 'stdout', false));85test('Prints IPC, verbose custom, fd-specific stdout+fd3, single function', () => testPrintIpcFunction('stdout', 'fd3', false));86test('Prints IPC, verbose custom, fd-specific fd3+stdout, single function', () => testPrintIpcFunction('fd3', 'stdout', false));87test('Prints IPC, verbose custom, fd-specific stdout+ipc, single function', () => testPrintIpcFunction('stdout', 'ipc', false));88test('Prints IPC, verbose custom, fd-specific ipc+stdout, single function', () => testPrintIpcFunction('ipc', 'stdout', true));89test('Prints IPC, verbose custom, fd-specific stderr+fd3, single function', () => testPrintIpcFunction('stderr', 'fd3', false));90test('Prints IPC, verbose custom, fd-specific fd3+stderr, single function', () => testPrintIpcFunction('fd3', 'stderr', false));91test('Prints IPC, verbose custom, fd-specific stderr+ipc, single function', () => testPrintIpcFunction('stderr', 'ipc', false));92test('Prints IPC, verbose custom, fd-specific ipc+stderr, single function', () => testPrintIpcFunction('ipc', 'stderr', true));93test('Prints IPC, verbose custom, fd-specific fd3+ipc, single function', () => testPrintIpcFunction('fd3', 'ipc', false));94test('Prints IPC, verbose custom, fd-specific ipc+fd3, single function', () => testPrintIpcFunction('ipc', 'fd3', true));

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

line 95why, one step back
95

TweaksSindre Sorhusbefore adoption698a1b8

line 96why, one step back
96test('"verbose" function receives verboseObject.message', async () => {

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 97–100why, one step back
97 const {stderr} = await runVerboseSubprocess({
98 type: 'ipc',99 eventProperty: 'message',100 });

TweaksSindre Sorhusbefore adoption698a1b8

line 101why, one step back
101 assert.equal(stderr, '. .');

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 102–103why, one step back
102});
103

TweaksSindre Sorhusbefore adoption698a1b8

line 104why, one step back
104test('"verbose" function receives verboseObject.message line-wise', async () => {

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 105–109why, one step back
105 const {stderr} = await runVerboseSubprocess({
106 optionsFixture: 'custom-print.js',107 type: 'ipc',108 output: '.\n.',109 });

TweaksSindre Sorhusbefore adoption698a1b8

line 110why, one step back
110 assert.deepEqual(getNormalizedLines(stderr), [`${testTimestamp} [0] * .`, `${testTimestamp} [0] * .`]);

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 111–112why, one step back
111});
112

TweaksSindre Sorhusbefore adoption698a1b8

line 113why, one step back
113test('"verbose" function receives verboseObject.message serialized', async () => {

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

lines 114–118why, one step back
114 const {stderr} = await nestedSubprocess('ipc-echo.js', {
115 ipcInput: foobarObject,116 optionsFixture: 'custom-print.js',117 optionsInput: {type: 'ipc'},118 });

TweaksSindre Sorhusbefore adoption698a1b8

line 119why, one step back
119 assert.equal(getNormalizedLine(stderr), `${testTimestamp} [0] * ${inspect(foobarObject)}`);

Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348

line 120why, one step back
120});