Skip to content
Myr

pending.js

This file

Path

test/ipc/pending.js

88 lines · 3.8 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';

Improve `buffer: false` option with IPC (#1094)ehmickybefore adoptiond8bdaf0

lines 2–3why, one step back
2import {once} from 'node:events';
3import {setTimeout} from 'node:timers/promises';

TweaksSindre Sorhusbefore adoption698a1b8

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

Improve `buffer: false` option with IPC (#1094)ehmickybefore adoptiond8bdaf0

lines 5–10why, one step back
5import {execa} from '../../index.js';
6import {setFixtureDirectory} from '../helpers/fixtures-directory.js';7import {foobarString} from '../helpers/input.js';89setFixtureDirectory();10

TweaksSindre Sorhusbefore adoption698a1b8

line 11why, one step back
11const testBufferInitial = async buffer => {

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

line 12why, one step back
12 const subprocess = execa('ipc-echo-wait.js', {buffer, ipcInput: foobarString});

TweaksSindre Sorhusbefore adoption698a1b8

line 13why, one step back
13 assert.equal(await subprocess.getOneMessage(), foobarString);

Improve `buffer: false` option with IPC (#1094)ehmickybefore adoptiond8bdaf0

lines 14–15why, one step back
14
15 const {ipcOutput} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 16why, one step back
16 assert.deepEqual(ipcOutput, buffer ? [foobarString] : []);

Improve `buffer: false` option with IPC (#1094)ehmickybefore adoptiond8bdaf0

lines 17–18why, one step back
17};
18

TweaksSindre Sorhusbefore adoption698a1b8

lines 19–20why, one step back
19test('Buffers initial message to subprocess, buffer false', () => testBufferInitial(false));
20test('Buffers initial message to subprocess, buffer true', () => testBufferInitial(true));

Improve `buffer: false` option with IPC (#1094)ehmickybefore adoptiond8bdaf0

line 21why, one step back
21

TweaksSindre Sorhusbefore adoption698a1b8

line 22why, one step back
22const testBufferInitialSend = async buffer => {

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

line 23why, one step back
23 const subprocess = execa('ipc-send-echo-wait.js', {buffer, ipcInput: foobarString});

TweaksSindre Sorhusbefore adoption698a1b8

lines 24–25why, one step back
24 assert.equal(await subprocess.getOneMessage(), '.');
25 assert.equal(await subprocess.getOneMessage(), foobarString);

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

lines 26–27why, one step back
26
27 const {ipcOutput} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 28why, one step back
28 assert.deepEqual(ipcOutput, buffer ? ['.', foobarString] : []);

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 31–32why, one step back
31test('sendMessage() does not empty the initial message buffering, buffer false', () => testBufferInitialSend(false));
32test('sendMessage() does not empty the initial message buffering, buffer true', () => testBufferInitialSend(true));

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

line 33why, one step back
33

TweaksSindre Sorhusbefore adoption698a1b8

line 34why, one step back
34const testBufferInitialStrict = async buffer => {

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

line 35why, one step back
35 const subprocess = execa('ipc-send-echo-strict.js', {buffer, ipcInput: foobarString});

TweaksSindre Sorhusbefore adoption698a1b8

line 36why, one step back
36 assert.equal(await subprocess.getOneMessage(), '.');

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

lines 37–39why, one step back
37 await setTimeout(1e3);
38 const promise = subprocess.getOneMessage();39 await subprocess.sendMessage('..');

TweaksSindre Sorhusbefore adoption698a1b8

line 40why, one step back
40 assert.equal(await promise, '..');

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

lines 41–42why, one step back
41
42 const {ipcOutput} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 43why, one step back
43 assert.deepEqual(ipcOutput, buffer ? ['.', '..'] : []);

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

lines 44–45why, one step back
44};
45

TweaksSindre Sorhusbefore adoption698a1b8

lines 46–47why, one step back
46test('sendMessage() with "strict" empties the initial message buffering, buffer false', () => testBufferInitialStrict(false));
47test('sendMessage() with "strict" empties the initial message buffering, buffer true', () => testBufferInitialStrict(true));

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

line 48why, one step back
48

TweaksSindre Sorhusbefore adoption698a1b8

line 49why, one step back
49const testNoBufferInitial = async buffer => {

Improve `buffer: false` option with IPC (#1094)ehmickybefore adoptiond8bdaf0

lines 50–51why, one step back
50 const subprocess = execa('ipc-send-print.js', {ipc: true, buffer});
51 const [chunk] = await once(subprocess.stdout, 'data');

TweaksSindre Sorhusbefore adoption698a1b8

line 52why, one step back
52 assert.equal(chunk.toString(), '.');

Improve `buffer: false` option with IPC (#1094)ehmickybefore adoptiond8bdaf0

line 53why, one step back
53 await setTimeout(1e3);

TweaksSindre Sorhusbefore adoption698a1b8

line 54why, one step back
54 assert.equal(await Promise.race([setTimeout(0), subprocess.getOneMessage()]), undefined);

Improve `buffer: false` option with IPC (#1094)ehmickybefore adoptiond8bdaf0

lines 55–57why, one step back
55 await subprocess.sendMessage('.');
5657 const {ipcOutput} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 58why, one step back
58 assert.deepEqual(ipcOutput, buffer ? [foobarString] : []);

Improve `buffer: false` option with IPC (#1094)ehmickybefore adoptiond8bdaf0

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 61–62why, one step back
61test('Does not buffer initial message to current process, buffer false', () => testNoBufferInitial(false));
62test('Does not buffer initial message to current process, buffer true', () => testNoBufferInitial(true));

Improve `buffer: false` option with IPC (#1094)ehmickybefore adoptiond8bdaf0

line 63why, one step back
63

TweaksSindre Sorhusbefore adoption698a1b8

line 64why, one step back
64const testReplay = async buffer => {

Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10

line 65why, one step back
65 const subprocess = execa('ipc-replay.js', {buffer, ipcInput: foobarString});

TweaksSindre Sorhusbefore adoption698a1b8

line 66why, one step back
66 assert.equal(await subprocess.getOneMessage(), foobarString);

Improve `buffer: false` option with IPC (#1094)ehmickybefore adoptiond8bdaf0

lines 67–69why, one step back
67 await subprocess.sendMessage('.');
68 await setTimeout(2e3);69 await subprocess.sendMessage(foobarString);

TweaksSindre Sorhusbefore adoption698a1b8

line 70why, one step back
70 assert.equal(await subprocess.getOneMessage(), foobarString);

Improve `buffer: false` option with IPC (#1094)ehmickybefore adoptiond8bdaf0

lines 71–72why, one step back
71
72 const {ipcOutput} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 73why, one step back
73 assert.deepEqual(ipcOutput, buffer ? [foobarString, foobarString] : []);

Improve `buffer: false` option with IPC (#1094)ehmickybefore adoptiond8bdaf0

lines 74–75why, one step back
74};
75

TweaksSindre Sorhusbefore adoption698a1b8

lines 76–77why, one step back
76test('Does not replay missed messages in subprocess, buffer false', () => testReplay(false));
77test('Does not replay missed messages in subprocess, buffer true', () => testReplay(true));

Improve `buffer: false` option with IPC (#1094)ehmickybefore adoptiond8bdaf0

line 78why, one step back
78

TweaksSindre Sorhusbefore adoption698a1b8

line 79why, one step back
79const testFastSend = async buffer => {

Improve `buffer: false` option with IPC (#1094)ehmickybefore adoptiond8bdaf0

line 80why, one step back
80 const subprocess = execa('ipc-send-native.js', {ipc: true, buffer});

TweaksSindre Sorhusbefore adoption698a1b8

line 81why, one step back
81 assert.equal(await subprocess.getOneMessage(), '.');

Improve `buffer: false` option with IPC (#1094)ehmickybefore adoptiond8bdaf0

lines 82–83why, one step back
82
83 const {ipcOutput} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

line 84why, one step back
84 assert.deepEqual(ipcOutput, buffer ? ['.'] : []);

Improve `buffer: false` option with IPC (#1094)ehmickybefore adoptiond8bdaf0

lines 85–86why, one step back
85};
86

TweaksSindre Sorhusbefore adoption698a1b8

lines 87–88why, one step back
87test('Subprocess can send messages right away, buffer false', () => testFastSend(false));
88test('Subprocess can send messages right away, buffer true', () => testFastSend(true));