Skip to content
Myr

ipc-input.js

This file

Path

test/ipc/ipc-input.js

85 lines · 4.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 {assertThrows, assertRejects} from '../helpers/assert.js';

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

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

TweaksSindre Sorhusbefore adoption698a1b8

line 10why, one step back
10const testSuccess = async options => {

Rename `result.ipc` to `result.ipcOutput` (#1075)ehmickybefore adoptionae9b360

line 11why, one step back
11 const {ipcOutput} = await execa('ipc-echo.js', {ipcInput: foobarString, ...options});

TweaksSindre Sorhusbefore adoption698a1b8

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

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 15–16why, one step back
15test('Sends a message with the "ipcInput" option, ipc undefined', () => testSuccess({}));
16test('Sends a message with the "ipcInput" option, ipc true', () => testSuccess({ipc: true}));

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

line 17why, one step back
17

TweaksSindre Sorhusbefore adoption698a1b8

lines 18–19why, one step back
18test('Cannot use the "ipcInput" option with "ipc" false', () => {
19 assertThrows(() => {

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

lines 20–23why, one step back
20 execa('empty.js', {ipcInput: foobarString, ipc: false});
21 }, {message: /unless the `ipc` option is `true`/});22});23

Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a

line 24why, one step back
24// Any value can be sent over IPC, including falsy ones, so those must be reported as `ipcInput`, not as `ipc`

TweaksSindre Sorhusbefore adoption698a1b8

lines 25–26why, one step back
25const testInvalidSyncIpcInput = ipcInput => {
26 assertThrows(() => {

Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a

line 27why, one step back
27 execaSync('empty.js', {ipcInput});

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

line 28why, one step back
28 }, {message: /The "ipcInput" option cannot be used with synchronous/});

Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a

line 29why, one step back
29};

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

line 30why, one step back
30

TweaksSindre Sorhusbefore adoption698a1b8

lines 31–35why, one step back
31test('Cannot use the "ipcInput" option with execaSync()', () => testInvalidSyncIpcInput(foobarString));
32test('Cannot use the "ipcInput" option with execaSync(), 0', () => testInvalidSyncIpcInput(0));33test('Cannot use the "ipcInput" option with execaSync(), empty string', () => testInvalidSyncIpcInput(''));34test('Cannot use the "ipcInput" option with execaSync(), false', () => testInvalidSyncIpcInput(false));35test('Cannot use the "ipcInput" option with execaSync(), null', () => testInvalidSyncIpcInput(null));

Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a

line 36why, one step back
36

TweaksSindre Sorhusbefore adoption698a1b8

lines 37–38why, one step back
37test('Invalid "ipcInput" option v8 format', () => {
38 const {message, cause} = assertThrows(() => {

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

lines 39–40why, one step back
39 execa('empty.js', {ipcInput() {}});
40 });

TweaksSindre Sorhusbefore adoption698a1b8

lines 41–42why, one step back
41 assert.equal(message, 'The `ipcInput` option is not serializable with a structured clone.');
42 assert.equal(cause.message, 'ipcInput() {} could not be cloned.');

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 45–46why, one step back
45test('Invalid "ipcInput" option JSON format', () => {
46 const {message, cause} = assertThrows(() => {

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

lines 47–48why, one step back
47 execa('empty.js', {ipcInput: 0n, serialization: 'json'});
48 });

TweaksSindre Sorhusbefore adoption698a1b8

lines 49–50why, one step back
49 assert.equal(message, 'The `ipcInput` option is not serializable with JSON.');
50 assert.equal(cause.message, 'Do not know how to serialize a BigInt');

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

line 51why, one step back
51});

Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a

lines 52–53why, one step back
52
53// `JSON.stringify()` returns `undefined`, instead of throwing, for values it cannot represent

TweaksSindre Sorhusbefore adoption698a1b8

lines 54–55why, one step back
54const testUnrepresentableJson = ipcInput => {
55 const {message} = assertThrows(() => {

Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a

lines 56–57why, one step back
56 execa('empty.js', {ipcInput, serialization: 'json', ipc: true});
57 });

TweaksSindre Sorhusbefore adoption698a1b8

line 58why, one step back
58 assert.equal(message, 'The `ipcInput` option is not serializable with JSON.');

Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 61–62why, one step back
61test('Invalid "ipcInput" option JSON format, function', () => testUnrepresentableJson(() => {}));
62test('Invalid "ipcInput" option JSON format, symbol', () => testUnrepresentableJson(Symbol('test')));

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

line 63why, one step back
63

Harden some thingsSindre Sorhusbefore adoption4a0a121

lines 64–65why, one step back
64// An invalid `serialization` option must not crash the `ipcInput` validation, which is keyed by it.
65// `Object.prototype` properties are the trickiest values, since those are found on any object.

TweaksSindre Sorhusbefore adoption698a1b8

lines 66–68why, one step back
66const testInvalidSerialization = async serialization => {
67 const {code} = await assertRejects(execa('empty.js', {ipcInput: foobarString, serialization}));68 assert.equal(code, 'ERR_INVALID_ARG_VALUE');

Harden some thingsSindre Sorhusbefore adoption4a0a121

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

TweaksSindre Sorhusbefore adoption698a1b8

lines 71–74why, one step back
71test('Invalid "serialization" option with the "ipcInput" option', () => testInvalidSerialization('invalid'));
72test('Invalid "serialization" option with the "ipcInput" option, __proto__', () => testInvalidSerialization('__proto__'));73test('Invalid "serialization" option with the "ipcInput" option, toString', () => testInvalidSerialization('toString'));74test('Invalid "serialization" option with the "ipcInput" option, constructor', () => testInvalidSerialization('constructor'));

Harden some thingsSindre Sorhusbefore adoption4a0a121

line 75why, one step back
75

TweaksSindre Sorhusbefore adoption698a1b8

lines 76–79why, one step back
76test('Handles "ipcInput" option during sending', async () => {
77 const {message, cause} = await assertRejects(execa('empty.js', {ipcInput: 0n}));78 assert.ok(message.includes('subprocess.sendMessage()\'s argument type is invalid: the message cannot be serialized: 0.'));79 assert.ok(cause.cause.message.includes('The "message" argument must be one of type string'));

Add `ipcInput` option (#1068)ehmickybefore adoption46cae30

line 80why, one step back
80});

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

line 81why, one step back
81

TweaksSindre Sorhusbefore adoption698a1b8

line 82why, one step back
82test('Can use "ipcInput" option even if the subprocess is not listening to messages', async () => {

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

line 83why, one step back
83 const {ipcOutput} = await execa('empty.js', {ipcInput: foobarString});

TweaksSindre Sorhusbefore adoption698a1b8

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

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

line 85why, one step back
85});