strict.js
This file
Path
test/ipc/strict.js
378 lines · 18.3 KiB · JavaScript
Last changed by
Fix IPC edge casesSindre Sorhusbefore adoption5f80cde
History of this fileTake it
TweaksSindre Sorhusbefore adoption698a1b8
line 1why, one step back1import assert from 'node:assert/strict';Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 2why, one step back2import {once} from 'node:events';TweaksSindre Sorhusbefore adoption698a1b8
lines 3–5why, one step back3import {setTimeout} from 'node:timers/promises';4import test from 'node:test';5import {assertRejects} from '../helpers/assert.js';Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 6–14why, one step back6import {execa} from '../../index.js';7import {setFixtureDirectory} from '../helpers/fixtures-directory.js';8import {foobarString} from '../helpers/input.js';9import {assertMaxListeners} from '../helpers/listeners.js';10import {subprocessGetOne, subprocessGetFirst, mockSendIoError} from '../helpers/ipc.js';11import {PARALLEL_COUNT} from '../helpers/parallel.js';1213setFixtureDirectory();14TweaksSindre Sorhusbefore adoption698a1b8
line 15why, one step back15const testStrictSuccessParentOne = async buffer => {Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 16–17why, one step back16 const subprocess = execa('ipc-echo.js', {ipc: true, buffer});17 await subprocess.sendMessage(foobarString, {strict: true});TweaksSindre Sorhusbefore adoption698a1b8
line 18why, one step back18 assert.equal(await subprocess.getOneMessage(), foobarString);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 19–20why, one step back1920 const {ipcOutput} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 21why, one step back21 assert.deepEqual(ipcOutput, buffer ? [foobarString] : []);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 22–23why, one step back22};23TweaksSindre Sorhusbefore adoption698a1b8
lines 24–25why, one step back24test('subprocess.sendMessage() "strict" succeeds if the subprocess uses exports.getOneMessage(), buffer false', () => testStrictSuccessParentOne(false));25test('subprocess.sendMessage() "strict" succeeds if the subprocess uses exports.getOneMessage(), buffer true', () => testStrictSuccessParentOne(true));Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 26why, one step back26TweaksSindre Sorhusbefore adoption698a1b8
line 27why, one step back27const testStrictSuccessParentEach = async buffer => {Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 28–29why, one step back28 const subprocess = execa('ipc-iterate.js', {ipc: true, buffer});29 await subprocess.sendMessage('.', {strict: true});TweaksSindre Sorhusbefore adoption698a1b8
line 30why, one step back30 assert.equal(await subprocess.getOneMessage(), '.');Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 31–33why, one step back31 await subprocess.sendMessage(foobarString);3233 const {ipcOutput} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 34why, one step back34 assert.deepEqual(ipcOutput, buffer ? ['.'] : []);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 35–36why, one step back35};36TweaksSindre Sorhusbefore adoption698a1b8
lines 37–38why, one step back37test('subprocess.sendMessage() "strict" succeeds if the subprocess uses exports.getEachMessage(), buffer false', () => testStrictSuccessParentEach(false));38test('subprocess.sendMessage() "strict" succeeds if the subprocess uses exports.getEachMessage(), buffer true', () => testStrictSuccessParentEach(true));Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 39why, one step back39Fix IPC edge casesSindre Sorhusbefore adoption5f80cde
lines 40–73why, one step back40// The message must not be wrapped with the `strict` metadata41test('subprocess.sendMessage() "strict" delivers the message if the subprocess disconnects before handling it', async () => {42 const subprocess = execa('ipc-get-strict-disconnect.js', {ipc: true});43 assert.equal(await subprocess.getOneMessage(), '.');44 await assertRejects(subprocess.sendMessage(foobarString, {strict: true}), {message: /^subprocess\.sendMessage\(\) failed: /});45 const {stdout} = await subprocess;46 assert.equal(stdout, JSON.stringify(foobarString));47});4849test('exports.sendMessage() "strict" delivers the message if the parent disconnects before handling it', async () => {50 const subprocess = execa('ipc-send-strict.js', {ipc: true, reject: false});51 subprocess.nodeChildProcess.once('message', () => {52 subprocess.nodeChildProcess.disconnect();53 });54 const {ipcOutput} = await subprocess;55 assert.deepEqual(ipcOutput, [foobarString]);56});5758// The acknowledgment cannot be sent back, but the message is still received59test('subprocess.sendMessage() "strict" delivers the message if the current process disconnects right after sending it', async () => {60 const subprocess = execa('ipc-get-print-ready.js', {ipc: true});61 assert.equal(await subprocess.getOneMessage(), '.');62 const sendPromise = subprocess.sendMessage(foobarString, {strict: true});63 subprocess.nodeChildProcess.disconnect();64 await assertRejects(sendPromise);65 const {stdout} = await subprocess;66 assert.equal(stdout, foobarString);67});6869test('exports.sendMessage() "strict" delivers the message if the subprocess disconnects right after sending it', async () => {70 const {ipcOutput} = await execa('ipc-send-strict-disconnect.js', {ipc: true});71 assert.deepEqual(ipcOutput, [foobarString]);72});73TweaksSindre Sorhusbefore adoption698a1b8
line 74why, one step back74const testStrictMissingParent = async buffer => {Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 75–77why, one step back75 const subprocess = execa('ipc-echo-twice.js', {ipcInput: foobarString, buffer});76 const promise = subprocess.getOneMessage();77 const secondPromise = subprocess.sendMessage(foobarString, {strict: true});TweaksSindre Sorhusbefore adoption698a1b8
lines 78–80why, one step back78 const {message} = await assertRejects(subprocess.sendMessage(foobarString, {strict: true}));79 assert.equal(message, 'subprocess.sendMessage() failed: the subprocess is not listening to incoming messages.');80 assert.equal(await promise, foobarString);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 81–83why, one step back81 await secondPromise;8283 const {ipcOutput} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 84why, one step back84 assert.deepEqual(ipcOutput, buffer ? [foobarString, foobarString] : []);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 85–86why, one step back85};86TweaksSindre Sorhusbefore adoption698a1b8
lines 87–88why, one step back87test('subprocess.sendMessage() "strict" fails if the subprocess is not listening, buffer false', () => testStrictMissingParent(false));88test('subprocess.sendMessage() "strict" fails if the subprocess is not listening, buffer true', () => testStrictMissingParent(true));Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 89why, one step back89TweaksSindre Sorhusbefore adoption698a1b8
line 90why, one step back90const testStrictExit = async buffer => {Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 91why, one step back91 const subprocess = execa('ipc-send.js', {ipc: true, buffer});TweaksSindre Sorhusbefore adoption698a1b8
lines 92–93why, one step back92 const {message} = await assertRejects(subprocess.sendMessage(foobarString, {strict: true}));93 assert.equal(message, 'subprocess.sendMessage() failed: the subprocess exited without listening to incoming messages.');Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 94–95why, one step back9495 const {ipcOutput} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 96why, one step back96 assert.deepEqual(ipcOutput, buffer ? [foobarString] : []);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 97–98why, one step back97};98TweaksSindre Sorhusbefore adoption698a1b8
lines 99–100why, one step back99test('subprocess.sendMessage() "strict" fails if the subprocess exits, buffer false', () => testStrictExit(false));100test('subprocess.sendMessage() "strict" fails if the subprocess exits, buffer true', () => testStrictExit(true));Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 101why, one step back101TweaksSindre Sorhusbefore adoption698a1b8
line 102why, one step back102const testStrictSuccessSubprocess = async (getMessage, buffer) => {Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 103why, one step back103 const subprocess = execa('ipc-send-strict.js', {ipc: true, buffer});TweaksSindre Sorhusbefore adoption698a1b8
line 104why, one step back104 assert.equal(await getMessage(subprocess), foobarString);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 105–106why, one step back105106 const {ipcOutput} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 107why, one step back107 assert.deepEqual(ipcOutput, buffer ? [foobarString] : []);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 108–109why, one step back108};109TweaksSindre Sorhusbefore adoption698a1b8
lines 110–113why, one step back110test('exports.sendMessage() "strict" succeeds if the current process uses subprocess.getOneMessage(), buffer false', () => testStrictSuccessSubprocess(subprocessGetOne, false));111test('exports.sendMessage() "strict" succeeds if the current process uses subprocess.getOneMessage(), buffer true', () => testStrictSuccessSubprocess(subprocessGetOne, true));112test('exports.sendMessage() "strict" succeeds if the current process uses subprocess.getEachMessage(), buffer false', () => testStrictSuccessSubprocess(subprocessGetFirst, false));113test('exports.sendMessage() "strict" succeeds if the current process uses subprocess.getEachMessage(), buffer true', () => testStrictSuccessSubprocess(subprocessGetFirst, true));Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 114why, one step back114TweaksSindre Sorhusbefore adoption698a1b8
line 115why, one step back115test('exports.sendMessage() "strict" succeeds if the current process uses result.ipcOutput', async () => {Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 116why, one step back116 const {ipcOutput} = await execa('ipc-send-strict.js', {ipc: true});TweaksSindre Sorhusbefore adoption698a1b8
line 117why, one step back117 assert.deepEqual(ipcOutput, [foobarString]);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 118–119why, one step back118});119TweaksSindre Sorhusbefore adoption698a1b8
lines 120–125why, one step back120test('exports.sendMessage() "strict" fails if the current process is not listening, buffer false', async () => {121 const {exitCode, isTerminated, stderr, ipcOutput} = await assertRejects(execa('ipc-send-strict.js', {ipc: true, buffer: {ipc: false}}));122 assert.equal(exitCode, 1);123 assert.equal(isTerminated, false);124 assert.ok(stderr.includes('Error: sendMessage() failed: the parent process is not listening to incoming messages.'));125 assert.deepEqual(ipcOutput, []);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 126–127why, one step back126});127TweaksSindre Sorhusbefore adoption698a1b8
lines 128–129why, one step back128test('Multiple subprocess.sendMessage() "strict" at once', async () => {129 const checkMaxListeners = assertMaxListeners();Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 130–136why, one step back130131 const subprocess = execa('ipc-iterate.js', {ipc: true});132 const messages = Array.from({length: PARALLEL_COUNT}, (_, index) => index);133 await Promise.all(messages.map(message => subprocess.sendMessage(message, {strict: true})));134 await subprocess.sendMessage(foobarString);135136 const {ipcOutput} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 137why, one step back137 assert.deepEqual(ipcOutput, messages);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 138–141why, one step back138139 checkMaxListeners();140});141TweaksSindre Sorhusbefore adoption698a1b8
line 142why, one step back142test('subprocess.sendMessage() "strict" fails if the subprocess uses once()', async () => {Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 143why, one step back143 const subprocess = execa('ipc-once-message.js', {ipc: true});TweaksSindre Sorhusbefore adoption698a1b8
lines 144–145why, one step back144 const {message} = await assertRejects(subprocess.sendMessage(foobarString, {strict: true}));145 assert.equal(message, 'subprocess.sendMessage() failed: the subprocess exited without listening to incoming messages.');Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 146–147why, one step back146147 const {ipcOutput} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 148why, one step back148 assert.deepEqual(ipcOutput, ['.']);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 149–150why, one step back149});150TweaksSindre Sorhusbefore adoption698a1b8
line 151why, one step back151test('exports.sendMessage() "strict" fails if the current process uses once() and buffer false', async () => {Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 152why, one step back152 const subprocess = execa('ipc-send-strict.js', {ipc: true, buffer: {ipc: false}});Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 153why, one step back153 const [message] = await once(subprocess.nodeChildProcess, 'message');TweaksSindre Sorhusbefore adoption698a1b8
line 154why, one step back154 assert.deepEqual(message, {Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a
line 155why, one step back155 id: 0,Fix deadlocks with IPC (#1104)ehmickybefore adoption465e427
lines 156–159why, one step back156 type: 'execa:ipc:request',157 message: foobarString,158 hasListeners: false,159 });Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 160why, one step back160TweaksSindre Sorhusbefore adoption698a1b8
lines 161–165why, one step back161 const {exitCode, isTerminated, stderr, ipcOutput} = await assertRejects(subprocess);162 assert.equal(exitCode, 1);163 assert.equal(isTerminated, false);164 assert.ok(stderr.includes('Error: sendMessage() failed: the parent process is not listening to incoming messages.'));165 assert.deepEqual(ipcOutput, []);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 166–167why, one step back166});167TweaksSindre Sorhusbefore adoption698a1b8
line 168why, one step back168test('subprocess.sendMessage() "strict" failure disconnects', async () => {Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 169–171why, one step back169 const subprocess = execa('ipc-echo-twice-wait.js', {ipcInput: foobarString});170 const promise = subprocess.getOneMessage();171 const secondPromise = subprocess.sendMessage(foobarString, {strict: true});TweaksSindre Sorhusbefore adoption698a1b8
lines 172–174why, one step back172 const {message} = await assertRejects(subprocess.sendMessage(foobarString, {strict: true}));173 assert.equal(message, 'subprocess.sendMessage() failed: the subprocess is not listening to incoming messages.');174 assert.equal(await promise, foobarString);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 175–176why, one step back175 await secondPromise;176TweaksSindre Sorhusbefore adoption698a1b8
lines 177–181why, one step back177 const {exitCode, isTerminated, stderr, ipcOutput} = await assertRejects(subprocess);178 assert.equal(exitCode, 1);179 assert.equal(isTerminated, false);180 assert.ok(stderr.includes('Error: sendMessage() cannot be used: the parent process has already exited or disconnected.'));181 assert.deepEqual(ipcOutput, [foobarString, foobarString]);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 182–183why, one step back182});183TweaksSindre Sorhusbefore adoption698a1b8
lines 184–189why, one step back184test('exports.sendMessage() "strict" failure disconnects', async () => {185 const {exitCode, isTerminated, stderr, ipcOutput} = await assertRejects(execa('ipc-send-strict-catch.js', {ipc: true, buffer: {ipc: false}}));186 assert.equal(exitCode, 1);187 assert.equal(isTerminated, false);188 assert.ok(stderr.includes('Error: sendMessage() cannot be used: the parent process has already exited or disconnected.'));189 assert.deepEqual(ipcOutput, []);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 190–191why, one step back190});191TweaksSindre Sorhusbefore adoption698a1b8
line 192why, one step back192const testIoErrorParent = async getMessage => {Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 193–194why, one step back193 const subprocess = execa('ipc-send-strict.js', {ipc: true});194 const cause = mockSendIoError(subprocess);TweaksSindre Sorhusbefore adoption698a1b8
lines 195–197why, one step back195 const error = await assertRejects(getMessage(subprocess));196 assert.ok(error.message.includes('subprocess.sendMessage() failed when sending an acknowledgment response to the subprocess.'));197 assert.equal(getMessage === subprocessGetOne ? error.cause : error.cause.cause, cause);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 198why, one step back198TweaksSindre Sorhusbefore adoption698a1b8
lines 199–203why, one step back199 const {exitCode, isTerminated, stderr, ipcOutput} = await assertRejects(subprocess);200 assert.equal(exitCode, 1);201 assert.equal(isTerminated, false);202 assert.ok(stderr.includes('Error: sendMessage() failed: the parent process exited without listening to incoming messages.'));203 assert.deepEqual(ipcOutput, []);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 204–205why, one step back204};205TweaksSindre Sorhusbefore adoption698a1b8
lines 206–207why, one step back206test('subprocess.getOneMessage() acknowledgment I/O error', () => testIoErrorParent(subprocessGetOne));207test('subprocess.getEachMessage() acknowledgment I/O error', () => testIoErrorParent(subprocessGetFirst));Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 208why, one step back208TweaksSindre Sorhusbefore adoption698a1b8
line 209why, one step back209const testIoErrorSubprocess = async fixtureName => {Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 210why, one step back210 const subprocess = execa(fixtureName, {ipc: true});TweaksSindre Sorhusbefore adoption698a1b8
lines 211–212why, one step back211 const {message} = await assertRejects(subprocess.sendMessage(foobarString, {strict: true}));212 assert.equal(message, 'subprocess.sendMessage() failed: the subprocess exited without listening to incoming messages.');Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 213why, one step back213TweaksSindre Sorhusbefore adoption698a1b8
lines 214–220why, one step back214 const {exitCode, isTerminated, stdout, stderr, ipcOutput} = await assertRejects(subprocess);215 assert.equal(exitCode, 1);216 assert.equal(isTerminated, false);217 assert.equal(stdout, '');218 assert.ok(stderr.includes('Error: sendMessage() failed when sending an acknowledgment response to the parent process.'));219 assert.ok(stderr.includes(`Error: ${foobarString}`));220 assert.deepEqual(ipcOutput, []);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 221–222why, one step back221};222TweaksSindre Sorhusbefore adoption698a1b8
lines 223–224why, one step back223test('exports.getOneMessage() acknowledgment I/O error', () => testIoErrorSubprocess('ipc-get-io-error.js'));224test('exports.getEachMessage() acknowledgment I/O error', () => testIoErrorSubprocess('ipc-iterate-io-error.js'));Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 225why, one step back225TweaksSindre Sorhusbefore adoption698a1b8
line 226why, one step back226test('Opposite sendMessage() "strict", buffer true', async () => {Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 227–230why, one step back227 const subprocess = execa('ipc-send-strict-get.js', {ipc: true});228 await subprocess.sendMessage(foobarString, {strict: true});229230 const {ipcOutput} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 231why, one step back231 assert.deepEqual(ipcOutput, [foobarString, foobarString]);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 232–233why, one step back232});233TweaksSindre Sorhusbefore adoption698a1b8
line 234why, one step back234test('Opposite sendMessage() "strict", current process listening, buffer false', async () => {Fix deadlocks with IPC (#1104)ehmickybefore adoption465e427
line 235why, one step back235 const subprocess = execa('ipc-send-strict-get.js', {ipc: true, buffer: {ipc: false}});Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 236–239why, one step back236 const [message] = await Promise.all([237 subprocess.getOneMessage(),238 subprocess.sendMessage(foobarString, {strict: true}),239 ]);TweaksSindre Sorhusbefore adoption698a1b8
lines 240–241why, one step back240 assert.equal(message, foobarString);241 assert.equal(await subprocess.getOneMessage(), foobarString);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 242–243why, one step back242243 const {ipcOutput} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 244why, one step back244 assert.deepEqual(ipcOutput, []);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 245–246why, one step back245});246TweaksSindre Sorhusbefore adoption698a1b8
line 247why, one step back247test('Opposite sendMessage() "strict", subprocess listening, buffer false', async () => {Fix deadlocks with IPC (#1104)ehmickybefore adoption465e427
line 248why, one step back248 const subprocess = execa('ipc-send-strict-listen.js', {ipc: true, buffer: {ipc: false}});Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 249why, one step back249 await subprocess.sendMessage(foobarString, {strict: true});TweaksSindre Sorhusbefore adoption698a1b8
line 250why, one step back250 assert.equal(await subprocess.getOneMessage(), foobarString);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 251–252why, one step back251252 const {ipcOutput} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 253why, one step back253 assert.deepEqual(ipcOutput, []);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
lines 254–255why, one step back254});255TweaksSindre Sorhusbefore adoption698a1b8
line 256why, one step back256test('Opposite sendMessage() "strict", not listening, buffer false', async () => {Fix deadlocks with IPC (#1104)ehmickybefore adoption465e427
line 257why, one step back257 const subprocess = execa('ipc-send-strict.js', {ipc: true, buffer: {ipc: false}});TweaksSindre Sorhusbefore adoption698a1b8
lines 258–259why, one step back258 const {message} = await assertRejects(subprocess.sendMessage(foobarString, {strict: true}));259 assert.ok(message.startsWith('subprocess.sendMessage() failed: the subprocess is sending a message too, instead of listening to incoming messages.'));Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 260why, one step back260TweaksSindre Sorhusbefore adoption698a1b8
lines 261–265why, one step back261 const {exitCode, isTerminated, stderr, ipcOutput} = await assertRejects(subprocess);262 assert.equal(exitCode, 1);263 assert.equal(isTerminated, false);264 assert.ok(stderr.includes('Error: sendMessage() failed: the parent process is sending a message too, instead of listening to incoming messages.'));265 assert.deepEqual(ipcOutput, []);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 266why, one step back266});Harden some thingsSindre Sorhusbefore adoption4a0a121
line 267why, one step back267TweaksSindre Sorhusbefore adoption698a1b8
line 268why, one step back268test('Ignores "strict" responses with an Object.prototype property as id', async () => {Harden some thingsSindre Sorhusbefore adoption4a0a121
line 269why, one step back269 const {ipcOutput} = await execa('ipc-send-strict-proto.js', {ipc: true});TweaksSindre Sorhusbefore adoption698a1b8
line 270why, one step back270 assert.deepEqual(ipcOutput, []);Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a
lines 271–272why, one step back271});272TweaksSindre Sorhusbefore adoption698a1b8
lines 273–289why, one step back273// `forever.js` does not use Execa, so it never acknowledges the message274test('Ignores "strict" responses sent by another subprocess', async () => {275 const subprocess = execa('forever.js', {ipc: true});276 const sendPromise = subprocess.sendMessage(foobarString, {strict: true});277278 try {279 const {ipcOutput} = await execa('ipc-send-strict-forged.js', {ipc: true});280 assert.deepEqual(ipcOutput, []);281 assert.equal(await Promise.race([sendPromise.then(() => 'resolved'), setTimeout(500, 'pending')]), 'pending');282 } finally {283 subprocess.kill();284 }285286 await Promise.all([assertRejects(sendPromise), assertRejects(subprocess)]);287});288289const testStrictJson = async buffer => {Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a
lines 290–291why, one step back290 const subprocess = execa('ipc-echo.js', {ipc: true, serialization: 'json', buffer});291 await subprocess.sendMessage(foobarString, {strict: true});TweaksSindre Sorhusbefore adoption698a1b8
line 292why, one step back292 assert.equal(await subprocess.getOneMessage(), foobarString);Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a
lines 293–294why, one step back293294 const {ipcOutput} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 295why, one step back295 assert.deepEqual(ipcOutput, buffer ? [foobarString] : []);Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a
lines 296–297why, one step back296};297TweaksSindre Sorhusbefore adoption698a1b8
lines 298–299why, one step back298test('subprocess.sendMessage() "strict" works with serialization "json", buffer false', () => testStrictJson(false));299test('subprocess.sendMessage() "strict" works with serialization "json", buffer true', () => testStrictJson(true));Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a
line 300why, one step back300TweaksSindre Sorhusbefore adoption698a1b8
line 301why, one step back301test('exports.sendMessage() "strict" works with serialization "json"', async () => {Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a
lines 302–305why, one step back302 const subprocess = execa('ipc-send-strict-get.js', {ipc: true, serialization: 'json'});303 await subprocess.sendMessage(foobarString, {strict: true});304305 const {ipcOutput} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 306why, one step back306 assert.deepEqual(ipcOutput, [foobarString, foobarString]);Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a
lines 307–308why, one step back307});308TweaksSindre Sorhusbefore adoption698a1b8
line 309why, one step back309test('subprocess.sendMessage() "strict" fails with serialization "json" if the subprocess is not listening', async () => {Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a
line 310why, one step back310 const subprocess = execa('ipc-send.js', {ipc: true, serialization: 'json'});TweaksSindre Sorhusbefore adoption698a1b8
lines 311–312why, one step back311 const {message} = await assertRejects(subprocess.sendMessage(foobarString, {strict: true}));312 assert.equal(message, 'subprocess.sendMessage() failed: the subprocess exited without listening to incoming messages.');Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a
lines 313–314why, one step back313314 const {ipcOutput} = await subprocess;TweaksSindre Sorhusbefore adoption698a1b8
line 315why, one step back315 assert.deepEqual(ipcOutput, [foobarString]);Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a
lines 316–322why, one step back316});317318const noop = () => {};319320// Messages received in the same batch are processed one after the other.321// The deadlock must be detected on the message being processed, not on the first one received.322// Without the detection, the subprocess would deadlock, so the `timeout` turns that hang into a failed assertion.TweaksSindre Sorhusbefore adoption698a1b8
line 323why, one step back323test('Detects a "strict" deadlock on a later message of the same batch', async () => {Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a
lines 324–327why, one step back324 const subprocess = execa('ipc-echo-strict-deadlock.js', {ipc: true, buffer: {ipc: false}, timeout: 1e4});325 await subprocess.sendMessage(foobarString);326 subprocess.sendMessage(foobarString, {strict: true}).catch(noop);327TweaksSindre Sorhusbefore adoption698a1b8
lines 328–332why, one step back328 const {exitCode, timedOut, stderr, ipcOutput} = await assertRejects(subprocess);329 assert.equal(timedOut, false);330 assert.equal(exitCode, 1);331 assert.ok(stderr.includes('Error: sendMessage() failed: the parent process is sending a message too, instead of listening to incoming messages.'));332 assert.deepEqual(ipcOutput, []);Fix IPC edge casesSindre Sorhusbefore adoption5f80cde
lines 333–377why, one step back333});334335// Messages which look like Execa's internal `strict` messages but are sent without the `strict` option are user messages.336// They must not wait for an acknowledgment response, and must be delivered as is.337test('sendMessage() does not wait for an acknowledgment response unless the "strict" option is true', async () => {338 const subprocess = execa('forever.js', {ipc: true});339 const message = {340 type: 'execa:ipc:request',341 id: 0,342 message: foobarString,343 hasListeners: false,344 };345346 try {347 await subprocess.sendMessage(message);348 } finally {349 subprocess.kill();350 }351352 await assertRejects(subprocess);353});354355test('Messages with the internal "strict" request type are kept as is', async () => {356 const message = {357 type: 'execa:ipc:request',358 };359 const {ipcOutput} = await execa('ipc-send-object.js', [JSON.stringify(message)], {ipc: true});360 assert.deepEqual(ipcOutput, [message]);361});362363test('Messages with the internal "strict" request type are kept as is, from the parent', async () => {364 const message = {365 type: 'execa:ipc:request',366 message: foobarString,367 };368 const {ipcOutput} = await execa('ipc-echo.js', {ipcInput: message});369 assert.deepEqual(ipcOutput, [message]);370});371372test('Messages with the internal "strict" request type do not fail pending "strict" sends', async () => {373 const subprocess = execa('ipc-send-object.js', [JSON.stringify({type: 'execa:ipc:request'})], {ipc: true, buffer: {ipc: false}});374 const sendPromise = subprocess.sendMessage(foobarString, {strict: true});375 const {message} = await assertRejects(sendPromise);376 assert.equal(message, 'subprocess.sendMessage() failed: the subprocess exited without listening to incoming messages.');377 await subprocess;Harden some thingsSindre Sorhusbefore adoption4a0a121
line 378why, one step back378});