Skip to content
Myr

reference.js

This file

Path

test/ipc/reference.js

132 lines · 5.2 KiB · JavaScript

Last changed by

TweaksSindre Sorhusbefore adoption698a1b8

History of this file

Take it

TweaksSindre Sorhusbefore adoption698a1b8

lines 1–3why, one step back
1import assert from 'node:assert/strict';
2import test from 'node:test';3import {assertRejects} from '../helpers/assert.js';

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 11–13why, one step back
11const testReference = async fixtureName => {
12 const {timedOut} = await assertRejects(execa(fixtureName, {ipc: true, timeout: 1e3}));13 assert.equal(timedOut, true);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 14–15why, one step back
14};
15

TweaksSindre Sorhusbefore adoption698a1b8

lines 16–17why, one step back
16test('exports.getOneMessage() keeps the subprocess alive', () => testReference('ipc-get-ref.js'));
17test('exports.getEachMessage() keeps the subprocess alive', () => testReference('ipc-iterate-ref.js'));

Add `reference` option to `getOneMessage()` and `getEachMessage()` (#1107)ehmickybefore adoptionff02af6

line 18why, one step back
18

TweaksSindre Sorhusbefore adoption698a1b8

line 19why, one step back
19const testUnreference = async fixtureName => {

Add `reference` option to `getOneMessage()` and `getEachMessage()` (#1107)ehmickybefore adoptionff02af6

line 20why, one step back
20 const {ipcOutput} = await execa(fixtureName, {ipc: true});

TweaksSindre Sorhusbefore adoption698a1b8

line 21why, one step back
21 assert.deepEqual(ipcOutput, []);

Add `reference` option to `getOneMessage()` and `getEachMessage()` (#1107)ehmickybefore adoptionff02af6

lines 22–23why, one step back
22};
23

TweaksSindre Sorhusbefore adoption698a1b8

lines 24–25why, one step back
24test('exports.getOneMessage() does not keep the subprocess alive, reference false', () => testUnreference('ipc-get-unref.js'));
25test('exports.getEachMessage() does not keep the subprocess alive, reference false', () => testUnreference('ipc-iterate-unref.js'));

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 26why, one step back
26

TweaksSindre Sorhusbefore adoption698a1b8

line 27why, one step back
27test('exports.sendMessage() keeps the subprocess alive', async () => {

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 28–29why, one step back
28 const {ipcOutput} = await execa('ipc-send-repeat.js', [`${PARALLEL_COUNT}`], {ipc: true});
29 const expectedOutput = Array.from({length: PARALLEL_COUNT}, (_, index) => index);

TweaksSindre Sorhusbefore adoption698a1b8

line 30why, one step back
30 assert.deepEqual(ipcOutput, expectedOutput);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 31–32why, one step back
31});
32

TweaksSindre Sorhusbefore adoption698a1b8

line 33why, one step back
33test('process.send() keeps the subprocess alive', async () => {

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 34why, one step back
34 const {ipcOutput, stdout} = await execa('ipc-process-send.js', {ipc: true});

TweaksSindre Sorhusbefore adoption698a1b8

lines 35–36why, one step back
35 assert.deepEqual(ipcOutput, [foobarString]);
36 assert.equal(stdout, '.');

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 37–38why, one step back
37});
38

TweaksSindre Sorhusbefore adoption698a1b8

line 39why, one step back
39test('process.send() keeps the subprocess alive, after getOneMessage()', async () => {

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

line 40why, one step back
40 const {ipcOutput, stdout} = await execa('ipc-process-send-get.js', {ipcInput: 0});

TweaksSindre Sorhusbefore adoption698a1b8

lines 41–42why, one step back
41 assert.deepEqual(ipcOutput, [foobarString]);
42 assert.equal(stdout, '.');

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 43–44why, one step back
43});
44

TweaksSindre Sorhusbefore adoption698a1b8

line 45why, one step back
45test('process.send() keeps the subprocess alive, after sendMessage()', async () => {

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 46why, one step back
46 const {ipcOutput, stdout} = await execa('ipc-process-send-send.js', {ipc: true});

TweaksSindre Sorhusbefore adoption698a1b8

lines 47–48why, one step back
47 assert.deepEqual(ipcOutput, ['.', foobarString]);
48 assert.equal(stdout, '.');

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 49–50why, one step back
49});
50

TweaksSindre Sorhusbefore adoption698a1b8

line 51why, one step back
51test('process.once("message") keeps the subprocess alive', async () => {

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 52why, one step back
52 const subprocess = execa('ipc-once-message.js', {ipc: true});

TweaksSindre Sorhusbefore adoption698a1b8

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

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 54–56why, one step back
54 await subprocess.sendMessage(foobarString);
5556 const {ipcOutput, stdout} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

lines 57–58why, one step back
57 assert.deepEqual(ipcOutput, ['.']);
58 assert.equal(stdout, foobarString);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

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

TweaksSindre Sorhusbefore adoption698a1b8

line 61why, one step back
61test('process.once("message") keeps the subprocess alive, after sendMessage()', async () => {

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 62why, one step back
62 const subprocess = execa('ipc-once-message-send.js', {ipc: true});

TweaksSindre Sorhusbefore adoption698a1b8

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

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 64–66why, one step back
64 await subprocess.sendMessage(foobarString);
6566 const {ipcOutput, stdout} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

lines 67–68why, one step back
67 assert.deepEqual(ipcOutput, ['.']);
68 assert.equal(stdout, foobarString);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

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

TweaksSindre Sorhusbefore adoption698a1b8

line 71why, one step back
71test('process.once("message") keeps the subprocess alive, after getOneMessage()', async () => {

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 72–73why, one step back
72 const subprocess = execa('ipc-once-message-get.js', {ipc: true});
73 await subprocess.sendMessage('.');

TweaksSindre Sorhusbefore adoption698a1b8

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

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 75–77why, one step back
75 await subprocess.sendMessage(foobarString);
7677 const {ipcOutput, stdout} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

lines 78–79why, one step back
78 assert.deepEqual(ipcOutput, ['.']);
79 assert.equal(stdout, foobarString);

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

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

TweaksSindre Sorhusbefore adoption698a1b8

line 82why, one step back
82test('process.once("disconnect") keeps the subprocess alive', async () => {

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 83why, one step back
83 const subprocess = execa('ipc-once-disconnect.js', {ipc: true});

TweaksSindre Sorhusbefore adoption698a1b8

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

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 85why, one step back
85 subprocess.nodeChildProcess.disconnect();

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 86–87why, one step back
86
87 const {ipcOutput, stdout} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

lines 88–89why, one step back
88 assert.deepEqual(ipcOutput, ['.']);
89 assert.equal(stdout, '.');

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 90–91why, one step back
90});
91

TweaksSindre Sorhusbefore adoption698a1b8

line 92why, one step back
92test('process.once("disconnect") keeps the subprocess alive, after sendMessage()', async () => {

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 93why, one step back
93 const subprocess = execa('ipc-once-disconnect-send.js', {ipc: true});

TweaksSindre Sorhusbefore adoption698a1b8

lines 94–96why, one step back
94 assert.equal(await subprocess.getOneMessage(), '.');
95 // eslint-disable-next-line node-test/no-duplicate-assertions -- the same message is read twice on purpose96 assert.equal(await subprocess.getOneMessage(), '.');

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 97why, one step back
97 subprocess.nodeChildProcess.disconnect();

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 98–99why, one step back
98
99 const {ipcOutput, stdout} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

lines 100–101why, one step back
100 assert.deepEqual(ipcOutput, ['.', '.']);
101 assert.equal(stdout, '.');

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

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

TweaksSindre Sorhusbefore adoption698a1b8

line 104why, one step back
104test('process.once("disconnect") does not keep the subprocess alive, after getOneMessage()', async () => {

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 105–106why, one step back
105 const subprocess = execa('ipc-once-disconnect-get.js', {ipc: true});
106 await subprocess.sendMessage('.');

TweaksSindre Sorhusbefore adoption698a1b8

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

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 108why, one step back
108 subprocess.nodeChildProcess.disconnect();

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

lines 109–110why, one step back
109
110 const {ipcOutput, stdout} = await subprocess;

TweaksSindre Sorhusbefore adoption698a1b8

lines 111–112why, one step back
111 assert.deepEqual(ipcOutput, ['.']);
112 assert.equal(stdout, '.');

Debounce `message` events (#1087)ehmickybefore adoptione8bab97

line 113why, one step back
113});

Refactor reference counting with IPC (#1089)ehmickybefore adoption18e607c

line 114why, one step back
114

TweaksSindre Sorhusbefore adoption698a1b8

line 115why, one step back
115test('Can call subprocess.disconnect() right away', async () => {

Refactor reference counting with IPC (#1089)ehmickybefore adoption18e607c

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

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 117why, one step back
117 subprocess.nodeChildProcess.disconnect();

TweaksSindre Sorhusbefore adoption698a1b8

line 118why, one step back
118 assert.equal(subprocess.nodeChildProcess.channel, null);

Refactor reference counting with IPC (#1089)ehmickybefore adoption18e607c

line 119why, one step back
119

TweaksSindre Sorhusbefore adoption698a1b8

line 120why, one step back
120 await assertRejects(subprocess.getOneMessage(), {

Refactor reference counting with IPC (#1089)ehmickybefore adoption18e607c

lines 121–122why, one step back
121 message: /subprocess.getOneMessage\(\) could not complete/,
122 });

TweaksSindre Sorhusbefore adoption698a1b8

line 123why, one step back
123 await assertRejects(subprocess, {

Refactor reference counting with IPC (#1089)ehmickybefore adoption18e607c

lines 124–127why, one step back
124 message: /Error: sendMessage\(\) cannot be used/,
125 });126});127

TweaksSindre Sorhusbefore adoption698a1b8

lines 128–131why, one step back
128test('Can call process.disconnect() right away', async () => {
129 const {stdout, stderr} = await assertRejects(execa('ipc-disconnect-get.js', {ipc: true}));130 assert.equal(stdout, 'null');131 assert.ok(stderr.includes('Error: getOneMessage() cannot be used'));

Refactor reference counting with IPC (#1089)ehmickybefore adoption18e607c

line 132why, one step back
132});