ipc.js
This file
Path
test/verbose/ipc.js
126 lines · 5.1 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';Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
lines 2–3why, one step back2import {on} from 'node:events';3import {inspect} from 'node:util';TweaksSindre Sorhusbefore adoption698a1b8
lines 4–5why, one step back4import 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 back6import {execa} from '../../index.js';Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
line 7why, one step back7import {setFixtureDirectory} from '../helpers/fixtures-directory.js';Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454
line 8why, one step back8import {foobarString, foobarRed, foobarObject} from '../helpers/input.js';Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 9why, one step back9import {nestedSubprocess, nestedInstance} from '../helpers/nested.js';Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883
line 10why, one step back10import {fullStdio} from '../helpers/stdio.js';Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
lines 11–21why, one step back11import {12 getIpcLine,13 getIpcLines,14 testTimestamp,15 ipcNoneOption,16 ipcShortOption,17 ipcFullOption,18} from '../helpers/verbose.js';1920setFixtureDirectory();21TweaksSindre Sorhusbefore adoption698a1b8
line 22why, one step back22const testPrintIpc = async verbose => {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 23why, one step back23 const {stderr} = await nestedSubprocess('ipc-send.js', {ipc: true, verbose});TweaksSindre Sorhusbefore adoption698a1b8
line 24why, one step back24 assert.equal(getIpcLine(stderr), `${testTimestamp} [0] * ${foobarString}`);Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
lines 25–26why, one step back25};26TweaksSindre Sorhusbefore adoption698a1b8
lines 27–28why, one step back27test('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 back29TweaksSindre Sorhusbefore adoption698a1b8
lines 30–31why, one step back30test('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 back32 execa('ipc-send.js', {ipc: true, verbose: {fd3: 'full'}});33 });TweaksSindre Sorhusbefore adoption698a1b8
line 34why, one step back34 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 back35});36TweaksSindre Sorhusbefore adoption698a1b8
line 37why, one step back37test('verbose.fd3 does not affect IPC', async () => {Fix fd-specific options to account for `ipc` (#1241)Sindre Sorhusbefore adoptionb886883
line 38why, one step back38 const {nestedResult, stderr} = await nestedSubprocess('ipc-send.js', {ipc: true, verbose: {fd3: 'full'}, ...fullStdio});TweaksSindre Sorhusbefore adoption698a1b8
lines 39–40why, one step back39 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 back41});42TweaksSindre Sorhusbefore adoption698a1b8
line 43why, one step back43const testNoPrintIpc = async verbose => {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 44why, one step back44 const {stderr} = await nestedSubprocess('ipc-send.js', {ipc: true, verbose});TweaksSindre Sorhusbefore adoption698a1b8
line 45why, one step back45 assert.equal(getIpcLine(stderr), undefined);Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
lines 46–47why, one step back46};47TweaksSindre Sorhusbefore adoption698a1b8
lines 48–53why, one step back48test('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 back54TweaksSindre Sorhusbefore adoption698a1b8
line 55why, one step back55const testNoIpc = async ipc => {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 56why, one step back56 const {nestedResult, stderr} = await nestedSubprocess('ipc-send.js', {ipc, verbose: 'full'});TweaksSindre Sorhusbefore adoption698a1b8
lines 57–59why, one step back57 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 back60};61TweaksSindre Sorhusbefore adoption698a1b8
lines 62–63why, one step back62test('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 back64TweaksSindre Sorhusbefore adoption698a1b8
line 65why, one step back65test('Prints objects from IPC', async () => {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 66why, one step back66 const {stderr} = await nestedSubprocess('ipc-send-json.js', [JSON.stringify(foobarObject)], {ipc: true, verbose: 'full'});TweaksSindre Sorhusbefore adoption698a1b8
line 67why, one step back67 assert.equal(getIpcLine(stderr), `${testTimestamp} [0] * ${inspect(foobarObject)}`);Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
lines 68–69why, one step back68});69TweaksSindre Sorhusbefore adoption698a1b8
line 70why, one step back70test('Prints multiline arrays from IPC', async () => {Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
line 71why, one step back71 const bigArray = Array.from({length: 100}, (_, index) => index);Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 72why, one step back72 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 back73 const ipcLines = getIpcLines(stderr);TweaksSindre Sorhusbefore adoption698a1b8
lines 74–76why, one step back74 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 back77});78TweaksSindre Sorhusbefore adoption698a1b8
line 79why, one step back79test('Does not quote spaces from IPC', async () => {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 80why, one step back80 const {stderr} = await nestedSubprocess('ipc-send.js', ['foo bar'], {ipc: true, verbose: 'full'});TweaksSindre Sorhusbefore adoption698a1b8
line 81why, one step back81 assert.equal(getIpcLine(stderr), `${testTimestamp} [0] * foo bar`);Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
lines 82–83why, one step back82});83TweaksSindre Sorhusbefore adoption698a1b8
line 84why, one step back84test('Does not quote newlines from IPC', async () => {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 85why, one step back85 const {stderr} = await nestedSubprocess('ipc-send.js', ['foo\nbar'], {ipc: true, verbose: 'full'});TweaksSindre Sorhusbefore adoption698a1b8
line 86why, one step back86 assert.deepEqual(getIpcLines(stderr), [Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
lines 87–91why, one step back87 `${testTimestamp} [0] * foo`,88 `${testTimestamp} [0] * bar`,89 ]);90});91TweaksSindre Sorhusbefore adoption698a1b8
line 92why, one step back92test('Does not quote special punctuation from IPC', async () => {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 93why, one step back93 const {stderr} = await nestedSubprocess('ipc-send.js', ['%'], {ipc: true, verbose: 'full'});TweaksSindre Sorhusbefore adoption698a1b8
line 94why, one step back94 assert.equal(getIpcLine(stderr), `${testTimestamp} [0] * %`);Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
lines 95–96why, one step back95});96TweaksSindre Sorhusbefore adoption698a1b8
line 97why, one step back97test('Does not escape internal characters from IPC', async () => {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 98why, one step back98 const {stderr} = await nestedSubprocess('ipc-send.js', ['ã'], {ipc: true, verbose: 'full'});TweaksSindre Sorhusbefore adoption698a1b8
line 99why, one step back99 assert.equal(getIpcLine(stderr), `${testTimestamp} [0] * ã`);Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
lines 100–101why, one step back100});101TweaksSindre Sorhusbefore adoption698a1b8
line 102why, one step back102test('Strips color sequences from IPC', async () => {Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454
line 103why, one step back103 const {stderr} = await nestedSubprocess('ipc-send.js', [foobarRed], {ipc: true, verbose: 'full'});TweaksSindre Sorhusbefore adoption698a1b8
line 104why, one step back104 assert.equal(getIpcLine(stderr), `${testTimestamp} [0] * ${foobarString}`);Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
lines 105–106why, one step back105});106TweaksSindre Sorhusbefore adoption698a1b8
line 107why, one step back107test('Escapes control characters from IPC', async () => {Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454
line 108why, one step back108 const {stderr} = await nestedSubprocess('ipc-send.js', ['\u{1}'], {ipc: true, verbose: 'full'});TweaksSindre Sorhusbefore adoption698a1b8
line 109why, one step back109 assert.equal(getIpcLine(stderr), `${testTimestamp} [0] * \\u0001`);Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
lines 110–111why, one step back110});111TweaksSindre Sorhusbefore adoption698a1b8
line 112why, one step back112test('Prints IPC progressively', async () => {Refactor test helpers for the `verbose` option (#1128)ehmickybefore adoption18d320f
line 113why, one step back113 const subprocess = nestedInstance('ipc-send-forever.js', {ipc: true, verbose: 'full'});TweaksSindre Sorhusbefore adoption698a1b8
lines 114–115why, one step back114115 let ipcLine;Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
line 116why, one step back116 for await (const chunk of on(subprocess.stderr, 'data')) {TweaksSindre Sorhusbefore adoption698a1b8
line 117why, one step back117 ipcLine = getIpcLine(chunk.toString());Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
lines 118–122why, one step back118 if (ipcLine !== undefined) {119 break;120 }121 }122TweaksSindre Sorhusbefore adoption698a1b8
line 123why, one step back123 assert.equal(ipcLine, `${testTimestamp} [0] * ${foobarString}`);Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
line 124why, one step back124 subprocess.kill();TweaksSindre Sorhusbefore adoption698a1b8
line 125why, one step back125 await assertRejects(subprocess);Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
line 126why, one step back126});