Skip to content
Myr

ipc.js

This file

Path

test/verbose/ipc.js

126 lines · 5.1 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';

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

lines 2–3why, one step back
2import {on} from 'node:events';
3import {inspect} from 'node:util';

TweaksSindre Sorhusbefore adoption698a1b8

lines 4–5why, one step back
4import test from 'node:test';
5import {assertThrows, assertRejects} from '../helpers/assert.js';

Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883

line 6why, one step back
6import {execa} from '../../index.js';

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

line 7why, one step back
7import {setFixtureDirectory} from '../helpers/fixtures-directory.js';

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

line 8why, one step back
8import {foobarString, foobarRed, foobarObject} from '../helpers/input.js';

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

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

Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883

line 10why, one step back
10import {fullStdio} from '../helpers/stdio.js';

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

lines 11–21why, one step back
11import {
12 getIpcLine,13 getIpcLines,14 testTimestamp,15 ipcNoneOption,16 ipcShortOption,17 ipcFullOption,18} from '../helpers/verbose.js';1920setFixtureDirectory();21

TweaksSindre Sorhusbefore adoption698a1b8

line 22why, one step back
22const testPrintIpc = async verbose => {

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

line 23why, one step back
23 const {stderr} = await nestedSubprocess('ipc-send.js', {ipc: true, verbose});

TweaksSindre Sorhusbefore adoption698a1b8

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

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

lines 25–26why, one step back
25};
26

TweaksSindre Sorhusbefore adoption698a1b8

lines 27–28why, one step back
27test('Prints IPC, verbose "full"', () => testPrintIpc('full'));
28test('Prints IPC, verbose "full", fd-specific', () => testPrintIpc(ipcFullOption));

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

line 29why, one step back
29

TweaksSindre Sorhusbefore adoption698a1b8

lines 30–31why, one step back
30test('verbose.fd3 is invalid without stdio[3], even with ipc', () => {
31 const {message} = assertThrows(() => {

Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883

lines 32–33why, one step back
32 execa('ipc-send.js', {ipc: true, verbose: {fd3: 'full'}});
33 });

TweaksSindre Sorhusbefore adoption698a1b8

line 34why, one step back
34 assert.ok(message.includes('"verbose.fd3" is invalid: that file descriptor does not exist.'));

Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883

lines 35–36why, one step back
35});
36

TweaksSindre Sorhusbefore adoption698a1b8

line 37why, one step back
37test('verbose.fd3 does not affect IPC', async () => {

Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883

line 38why, one step back
38 const {nestedResult, stderr} = await nestedSubprocess('ipc-send.js', {ipc: true, verbose: {fd3: 'full'}, ...fullStdio});

TweaksSindre Sorhusbefore adoption698a1b8

lines 39–40why, one step back
39 assert.deepEqual(nestedResult.ipcOutput, [foobarString]);
40 assert.equal(getIpcLine(stderr), undefined);

Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883

lines 41–42why, one step back
41});
42

TweaksSindre Sorhusbefore adoption698a1b8

line 43why, one step back
43const testNoPrintIpc = async verbose => {

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

line 44why, one step back
44 const {stderr} = await nestedSubprocess('ipc-send.js', {ipc: true, verbose});

TweaksSindre Sorhusbefore adoption698a1b8

line 45why, one step back
45 assert.equal(getIpcLine(stderr), undefined);

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

lines 46–47why, one step back
46};
47

TweaksSindre Sorhusbefore adoption698a1b8

lines 48–53why, one step back
48test('Does not print IPC, verbose default', () => testNoPrintIpc(undefined));
49test('Does not print IPC, verbose "none"', () => testNoPrintIpc('none'));50test('Does not print IPC, verbose "short"', () => testNoPrintIpc('short'));51test('Does not print IPC, verbose default, fd-specific', () => testNoPrintIpc({}));52test('Does not print IPC, verbose "none", fd-specific', () => testNoPrintIpc(ipcNoneOption));53test('Does not print IPC, verbose "short", fd-specific', () => testNoPrintIpc(ipcShortOption));

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

line 54why, one step back
54

TweaksSindre Sorhusbefore adoption698a1b8

line 55why, one step back
55const testNoIpc = async ipc => {

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

line 56why, one step back
56 const {nestedResult, stderr} = await nestedSubprocess('ipc-send.js', {ipc, verbose: 'full'});

TweaksSindre Sorhusbefore adoption698a1b8

lines 57–59why, one step back
57 assert.ok(nestedResult instanceof Error);
58 assert.ok(nestedResult.message.includes('sendMessage() can only be used'));59 assert.equal(getIpcLine(stderr), undefined);

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

lines 60–61why, one step back
60};
61

TweaksSindre Sorhusbefore adoption698a1b8

lines 62–63why, one step back
62test('Does not print IPC, ipc: false', () => testNoIpc(false));
63test('Does not print IPC, ipc: default', () => testNoIpc(undefined));

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

line 64why, one step back
64

TweaksSindre Sorhusbefore adoption698a1b8

line 65why, one step back
65test('Prints objects from IPC', async () => {

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

line 66why, one step back
66 const {stderr} = await nestedSubprocess('ipc-send-json.js', [JSON.stringify(foobarObject)], {ipc: true, verbose: 'full'});

TweaksSindre Sorhusbefore adoption698a1b8

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

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

lines 68–69why, one step back
68});
69

TweaksSindre Sorhusbefore adoption698a1b8

line 70why, one step back
70test('Prints multiline arrays from IPC', async () => {

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

line 71why, one step back
71 const bigArray = Array.from({length: 100}, (_, index) => index);

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

line 72why, one step back
72 const {stderr} = await nestedSubprocess('ipc-send-json.js', [JSON.stringify(bigArray)], {ipc: true, verbose: 'full'});

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

line 73why, one step back
73 const ipcLines = getIpcLines(stderr);

TweaksSindre Sorhusbefore adoption698a1b8

lines 74–76why, one step back
74 assert.equal(ipcLines[0], `${testTimestamp} [0] * [`);
75 assert.equal(ipcLines.at(-2), `${testTimestamp} [0] * 96, 97, 98, 99`);76 assert.equal(ipcLines.at(-1), `${testTimestamp} [0] * ]`);

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

lines 77–78why, one step back
77});
78

TweaksSindre Sorhusbefore adoption698a1b8

line 79why, one step back
79test('Does not quote spaces from IPC', async () => {

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

line 80why, one step back
80 const {stderr} = await nestedSubprocess('ipc-send.js', ['foo bar'], {ipc: true, verbose: 'full'});

TweaksSindre Sorhusbefore adoption698a1b8

line 81why, one step back
81 assert.equal(getIpcLine(stderr), `${testTimestamp} [0] * foo bar`);

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

lines 82–83why, one step back
82});
83

TweaksSindre Sorhusbefore adoption698a1b8

line 84why, one step back
84test('Does not quote newlines from IPC', async () => {

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

line 85why, one step back
85 const {stderr} = await nestedSubprocess('ipc-send.js', ['foo\nbar'], {ipc: true, verbose: 'full'});

TweaksSindre Sorhusbefore adoption698a1b8

line 86why, one step back
86 assert.deepEqual(getIpcLines(stderr), [

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

lines 87–91why, one step back
87 `${testTimestamp} [0] * foo`,
88 `${testTimestamp} [0] * bar`,89 ]);90});91

TweaksSindre Sorhusbefore adoption698a1b8

line 92why, one step back
92test('Does not quote special punctuation from IPC', async () => {

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

line 93why, one step back
93 const {stderr} = await nestedSubprocess('ipc-send.js', ['%'], {ipc: true, verbose: 'full'});

TweaksSindre Sorhusbefore adoption698a1b8

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

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

lines 95–96why, one step back
95});
96

TweaksSindre Sorhusbefore adoption698a1b8

line 97why, one step back
97test('Does not escape internal characters from IPC', async () => {

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

line 98why, one step back
98 const {stderr} = await nestedSubprocess('ipc-send.js', ['ã'], {ipc: true, verbose: 'full'});

TweaksSindre Sorhusbefore adoption698a1b8

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

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

lines 100–101why, one step back
100});
101

TweaksSindre Sorhusbefore adoption698a1b8

line 102why, one step back
102test('Strips color sequences from IPC', async () => {

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

line 103why, one step back
103 const {stderr} = await nestedSubprocess('ipc-send.js', [foobarRed], {ipc: true, verbose: 'full'});

TweaksSindre Sorhusbefore adoption698a1b8

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

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

lines 105–106why, one step back
105});
106

TweaksSindre Sorhusbefore adoption698a1b8

line 107why, one step back
107test('Escapes control characters from IPC', async () => {

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

line 108why, one step back
108 const {stderr} = await nestedSubprocess('ipc-send.js', ['\u{1}'], {ipc: true, verbose: 'full'});

TweaksSindre Sorhusbefore adoption698a1b8

line 109why, one step back
109 assert.equal(getIpcLine(stderr), `${testTimestamp} [0] * \\u0001`);

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

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

TweaksSindre Sorhusbefore adoption698a1b8

line 112why, one step back
112test('Prints IPC progressively', async () => {

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

line 113why, one step back
113 const subprocess = nestedInstance('ipc-send-forever.js', {ipc: true, verbose: 'full'});

TweaksSindre Sorhusbefore adoption698a1b8

lines 114–115why, one step back
114
115 let ipcLine;

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

line 116why, one step back
116 for await (const chunk of on(subprocess.stderr, 'data')) {

TweaksSindre Sorhusbefore adoption698a1b8

line 117why, one step back
117 ipcLine = getIpcLine(chunk.toString());

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

lines 118–122why, one step back
118 if (ipcLine !== undefined) {
119 break;120 }121 }122

TweaksSindre Sorhusbefore adoption698a1b8

line 123why, one step back
123 assert.equal(ipcLine, `${testTimestamp} [0] * ${foobarString}`);

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

line 124why, one step back
124 subprocess.kill();

TweaksSindre Sorhusbefore adoption698a1b8

line 125why, one step back
125 await assertRejects(subprocess);

Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe

line 126why, one step back
126});