send.test-d.ts
This file
Path
test-d/ipc/send.test-d.ts
59 lines · 2.9 KiB · TypeScript
Last changed by
Fix `execaNode()` and the `node` option missing IPC in their typesSindre Sorhusbefore adoption2633abb
History of this fileTake it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import {expectTypeOf, expectError} from 'nz';import { sendMessage, execa, execaNode, type Message, type Options,} from '../../index.js';
const subprocess = execa('test', {ipc: true});expectTypeOf(await subprocess.sendMessage('')).toBe<void>();expectTypeOf(sendMessage('')).toBe<Promise<void>>();
expectError(await subprocess.sendMessage());expectError(await sendMessage());expectError(await subprocess.sendMessage(undefined));expectError(await sendMessage(undefined));expectError(await subprocess.sendMessage(0n));expectError(await sendMessage(0n));expectError(await subprocess.sendMessage(Symbol('test')));expectError(await sendMessage(Symbol('test')));
await execa('test', {ipcInput: ''}).sendMessage('');await execa('test', {ipcInput: '' as Message}).sendMessage('');await execa('test', {gracefulCancel: true, cancelSignal: AbortSignal.abort()}).sendMessage('');await execa('test', {node: true}).sendMessage('');await execaNode('test').sendMessage('');await execaNode({})`test`.sendMessage('');await execa('test', {} as Options).sendMessage?.('');await execa('test', {ipc: true as boolean}).sendMessage?.('');await execa('test', {ipcInput: '' as '' | undefined}).sendMessage?.('');await execa('test', {gracefulCancel: true as boolean | undefined, cancelSignal: AbortSignal.abort()}).sendMessage?.('');
expectTypeOf(execa('test').sendMessage).toBe<undefined>();expectTypeOf(execa('test', {}).sendMessage).toBe<undefined>();expectTypeOf(execa('test', {ipc: false}).sendMessage).toBe<undefined>();expectTypeOf(execa('test', {ipcInput: undefined}).sendMessage).toBe<undefined>();expectTypeOf(execa('test', {gracefulCancel: undefined}).sendMessage).toBe<undefined>();expectTypeOf(execa('test', {gracefulCancel: false}).sendMessage).toBe<undefined>();expectTypeOf(execa('test', {ipc: false, ipcInput: ''}).sendMessage).toBe<undefined>();expectTypeOf(execa('test', {ipc: false, gracefulCancel: true, cancelSignal: AbortSignal.abort()}).sendMessage).toBe<undefined>();expectTypeOf(execa('test', {node: false}).sendMessage).toBe<undefined>();expectTypeOf(execa('test', {ipc: false, node: true}).sendMessage).toBe<undefined>();expectTypeOf(execaNode('test', {ipc: false}).sendMessage).toBe<undefined>();
await subprocess.sendMessage('', {} as const);await sendMessage('', {} as const);await subprocess.sendMessage('', {strict: true} as const);await sendMessage('', {strict: true} as const);await subprocess.sendMessage('', {strict: true as boolean});await sendMessage('', {strict: true as boolean});expectError(await subprocess.sendMessage('', true));expectError(await sendMessage('', true));expectError(await subprocess.sendMessage('', {strict: 'true'}));expectError(await sendMessage('', {strict: 'true'}));expectError(await subprocess.sendMessage('', {unknown: true}));expectError(await sendMessage('', {unknown: true}));expectError(await subprocess.sendMessage('', {strict: true}, {}));expectError(await sendMessage('', {strict: true}, {}));