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 fileTake it
TweaksSindre Sorhusbefore adoption698a1b8
lines 1–3why, one step back1import 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 back4import {execa, execaSync} from '../../index.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {foobarString} from '../helpers/input.js';78setFixtureDirectory();9TweaksSindre Sorhusbefore adoption698a1b8
line 10why, one step back10const testSuccess = async options => {Rename `result.ipc` to `result.ipcOutput` (#1075)ehmickybefore adoptionae9b360
line 11why, one step back11 const {ipcOutput} = await execa('ipc-echo.js', {ipcInput: foobarString, ...options});TweaksSindre Sorhusbefore adoption698a1b8
line 12why, one step back12 assert.deepEqual(ipcOutput, [foobarString]);Add `ipcInput` option (#1068)ehmickybefore adoption46cae30
lines 13–14why, one step back13};14TweaksSindre Sorhusbefore adoption698a1b8
lines 15–16why, one step back15test('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 back17TweaksSindre Sorhusbefore adoption698a1b8
lines 18–19why, one step back18test('Cannot use the "ipcInput" option with "ipc" false', () => {19 assertThrows(() => {Add `ipcInput` option (#1068)ehmickybefore adoption46cae30
lines 20–23why, one step back20 execa('empty.js', {ipcInput: foobarString, ipc: false});21 }, {message: /unless the `ipc` option is `true`/});22});23Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a
line 24why, one step back24// 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 back25const testInvalidSyncIpcInput = ipcInput => {26 assertThrows(() => {Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a
line 27why, one step back27 execaSync('empty.js', {ipcInput});Add `ipcInput` option (#1068)ehmickybefore adoption46cae30
line 28why, one step back28 }, {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 back29};Add `ipcInput` option (#1068)ehmickybefore adoption46cae30
line 30why, one step back30TweaksSindre Sorhusbefore adoption698a1b8
lines 31–35why, one step back31test('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 back36TweaksSindre Sorhusbefore adoption698a1b8
lines 37–38why, one step back37test('Invalid "ipcInput" option v8 format', () => {38 const {message, cause} = assertThrows(() => {Add `ipcInput` option (#1068)ehmickybefore adoption46cae30
lines 39–40why, one step back39 execa('empty.js', {ipcInput() {}});40 });TweaksSindre Sorhusbefore adoption698a1b8
lines 41–42why, one step back41 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 back43});44TweaksSindre Sorhusbefore adoption698a1b8
lines 45–46why, one step back45test('Invalid "ipcInput" option JSON format', () => {46 const {message, cause} = assertThrows(() => {Add `ipcInput` option (#1068)ehmickybefore adoption46cae30
lines 47–48why, one step back47 execa('empty.js', {ipcInput: 0n, serialization: 'json'});48 });TweaksSindre Sorhusbefore adoption698a1b8
lines 49–50why, one step back49 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 back51});Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a
lines 52–53why, one step back5253// `JSON.stringify()` returns `undefined`, instead of throwing, for values it cannot representTweaksSindre Sorhusbefore adoption698a1b8
lines 54–55why, one step back54const testUnrepresentableJson = ipcInput => {55 const {message} = assertThrows(() => {Fix the `strict` and `ipcInput` options with the `serialization` optionSindre Sorhusbefore adoption9842f1a
lines 56–57why, one step back56 execa('empty.js', {ipcInput, serialization: 'json', ipc: true});57 });TweaksSindre Sorhusbefore adoption698a1b8
line 58why, one step back58 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 back59};60TweaksSindre Sorhusbefore adoption698a1b8
lines 61–62why, one step back61test('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 back63Harden some thingsSindre Sorhusbefore adoption4a0a121
lines 64–65why, one step back64// 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 back66const 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 back69};70TweaksSindre Sorhusbefore adoption698a1b8
lines 71–74why, one step back71test('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 back75TweaksSindre Sorhusbefore adoption698a1b8
lines 76–79why, one step back76test('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 back80});Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 81why, one step back81TweaksSindre Sorhusbefore adoption698a1b8
line 82why, one step back82test('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 back83 const {ipcOutput} = await execa('empty.js', {ipcInput: foobarString});TweaksSindre Sorhusbefore adoption698a1b8
line 84why, one step back84 assert.deepEqual(ipcOutput, []);Add `strict` option to `sendMessage()` (#1098)ehmickybefore adoptione085b10
line 85why, one step back85});